Combine single and multidimensional array using php -


I have 2 arrays and I have both arrays.If match to array 1 array 2 , then I would like to keep 0 for that element.

array 1

  $ weeks array = array ("P1", "P2", "P3", "P4"); Array ("P1", "123"), "1" => Array ("p1", "123"); array ("p2"); array 2  

array2

  $ dailyArr = array ("0" => , "125"), "2" => array ("P4", "126"));   

After joining, I would like to be like the last array

  $ finalArr = array ("0" => array ("p1", "Array (" p3 "," 0 ")," 3 "=> array (" p4 ", 123"), "1" => array ("P2", "125"), "2 "= & Gt;" 126 "));   

So I would like to include p3 in the final code.

Any indication / suggestions are very welcome Thanks in advance.

I do not know the shortest way to go there, but you can get all the p Compare weeks.

After receiving the differences, assign one, then sort them at the end.

  $ weeksArr = array ("p1" "p2", "p3", "p4"); $ DailyArr = array ("0" = & gt; array ("p1", "123"), "1" => array ("p2", "125"), "2" => array ( "P4", "126")); $ End hour = $ daily; $ Temp = array_map (function ($ piece) {piece of return dollar [0];}, $ finals arrr); // Get $ diff = array_diff ($ weekout, $ temp) of all p; // Get the missing P. ($ $ $ $ w) as {$ finalArr [] = array ($ w, 0); // unavailable P} usort ($ finalArr, function ($ a, $ b) {// You do not need it, you do not care about order return strcmp ($ a [0], $ b [0]) ; // If you need to order them, P1, P2, P3, P4, then I think you need to sort it}); Echo '& lt; Pre & gt; '; Print_r ($ finalArr);    

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -