Saturday, 15 February 2014

php - How to merge these two arrays in this specific order -



php - How to merge these two arrays in this specific order -

i have 2 array following

array ( [0] => 641 [1] => 622 [2] => 100 [3] => 6431 ) array ( [0] => 64.1 [1] => 62.2 [2] => 10 [3] => 643.1 )

how can create following

array ( [0] => 641 [1] => 64.1 [2] => 622 [3] => 62.2 [4] => 100 [5] => 10 [6] => 6431 [7] => 643.1 )

it's simple as

$result=array_merge($array1,$array2);

note: values wont in order presented though. if of import need loop through arrays build new array accordingly.

ummm ok here version well

if(count($array1)==count($array2)) { for($i=0;$i<count($array1);$i++) { $result[]=$array1[$i]; $result[]=$array2[$i]; } } print_r($result);

fiddle

manual

php arrays

No comments:

Post a Comment