note 80566 deleted from function.array-merge by nlopess
| From: | nlopess@php.net | Date: | Tue, 22 Jan 2008 19:56:43 +0000 |
| Subject: | note 80566 deleted from function.array-merge by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-135319@lists.php.net to get a copy of this message | ||
Note Submitter: horsewhip
----
I tried to use freed489's code to alternate-merge my two arrays together...
<?
function alternatly_merge_arrays($array1, $array2){
$combined_array = array();
$count = 0;
for($i = 0; $i < count($array1) + count($array2); $i = $i + 2){
$combined_array[$i] = $array1[$count];
$count++;
}//end for
$count = 0;
for($i = 1; $i < count($array1) + count($array2); $i = $i + 2){
$combined_array[$i] = $array2[$count];
$count++;
}//end for
return $combined_array;
}//end alternate_merge_arrays
?>
However its just coming out with one array appended on the other, just like the normal merge()
works. Does anyone have any ideas on merging two arrays like a deck of cards? Such as:
$array1 = {1,3,5,7};
$array2 = {2,4,6,8};
And then merge the two arrays so that final array would be $final_array = {1,2,3,4,5,6,7,8};
Any ideas?
Thanks all, love all the code snippets here!!