note 80566 added to function.array-merge
| From: | horsewhip at osu1 dot php dot net | Date: | Tue, 22 Jan 2008 19:47:42 +0000 |
| Subject: | note 80566 added to function.array-merge | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-135315@lists.php.net to get a copy of this message | ||
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!!
----
Server IP: 66.207.199.35
Probable Submitter: 76.75.67.136
----
Manual Page -- http://www.php.net/manual/en/function.array-merge.php
Edit -- https://master.php.net/note/edit/80566
Del: integrated -- https://master.php.net/note/delete/80566/integrated
Del: useless -- https://master.php.net/note/delete/80566/useless
Del: bad code -- https://master.php.net/note/delete/80566/bad+code
Del: spam -- https://master.php.net/note/delete/80566/spam
Del: non-english -- https://master.php.net/note/delete/80566/non-english
Del: in docs -- https://master.php.net/note/delete/80566/in+docs
Del: other reasons-- https://master.php.net/note/delete/80566
Reject -- https://master.php.net/note/reject/80566
Search -- https://master.php.net/manage/user-notes.php