PHP - How to combine two arrays with different number of elements? -


i have 2 arrays:

one:

array(4) {   [0]=> array(2) {       [0]=> string(19) "ford"       [1]=> string(1) "1"   }   [1]=> array(2) {       [0]=> string(15) "chevrolet"       [1]=> string(1) "1"   }   [2]=> array(2) {       [0]=> string(7) "vw"       [1]=> string(1) "1"   }   [3]=> array(2) {       [0]=> string(4) "fiat"       [1]=> string(1) "3"   }  } 

two:

array(6) {      [0]=> string(7) "#581845"      [1]=> string(7) "#900c3f"      [2]=> string(7) "#c70039"      [3]=> string(7) "#ff5733"      [4]=> string(7) "#ffc300"      [5]=> string(7) "#daf7a6"  } 

now, need first array combining second, excluding elements of second array not used first. @ end, want receive array like:

[0]=> {         [0]=> "ford",          [1]=> "1",          [2]=>"#581845"       }          [1]=>           ...        } 

provided have more colors auto makes, can this:

$makes = [     [         "ford",         "1"     ],     [         "chevrolet",         "1"     ],     [         "vw",         "1"     ],     [         "fiat",         "3"     ] ];  $colors = [     "#581845",     "#900c3f",     "#c70039",     "#ff5733",     "#ffc300",     "#daf7a6" ];  foreach($makes &$currmaketuple) {     $currmaketuple[] = array_shift($colors); }  print_r($makes);  array (     [0] => array         (             [0] => ford             [1] => 1             [2] => #581845         )      [1] => array         (             [0] => chevrolet             [1] => 1             [2] => #900c3f         )      [2] => array         (             [0] => vw             [1] => 1             [2] => #c70039         )      [3] => array         (             [0] => fiat             [1] => 3             [2] => #ff5733         )  ) 

you should check condition , have contingency it.


Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -