php - Merging arrays of different lengths -


given 2 arrays of following formats:

$array1 = array("1", "2", "3", "4", "5");  $array2 = array(   0 => array("start" => "09:00", "end" => "17:00"),   1 => array("start" => "18:00", "end" => "20:00") ); 

i need merge result is:

$result = array(   array(     "start_day" => "1",     "start_time" => "09:00",     "end_day" => "1",     "end_time" => "17:00"   ),   array(     "start_day" => "1",     "start_time" => "18:00",     "end_day" => "1",     "end_time" => "20:00"  )  // , on each item in $array1 ); 

both arrays can of varying lengths each item in $array2 must applied item in $array1. throwing out there see if has experience sort of merge. current solution gives me result array length equals length of $array2. working on insight appreciated!

like this:

$result = []; foreach($array1 $elem1) {   foreach($array2 $elem2) {     $result[] = array(       "start_day" => $elem1,       "start_time" => $elem2['start'],       "end_day" => $elem1,       "end_time" => $elem2['end']     );   } } 

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -