note 66292 added to function.array-merge

From: Date: Thu, 18 May 2006 15:32:25 +0000
Subject: note 66292 added to function.array-merge
Groups: php.notes 
Request: Send a blank email to php-notes+get-111595@lists.php.net to get a copy of this message
I needed a function to alternatly merge 2 arrays. i.e. $a1 = (a, c, e) and $a2 = (b, d, f), and now $merged = (a, b, c, d, e, f). Hope it helps... <? 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 ?> ---- Server IP: 64.71.164.2 Probable Submitter: 130.111.221.237 ---- X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/function.array-merge.php Edit -- http://master.php.net/note/edit/66292 Del: integrated -- http://master.php.net/note/delete/66292/integrated Del: useless -- http://master.php.net/note/delete/66292/useless Del: bad code -- http://master.php.net/note/delete/66292/bad+code Del: spam -- http://master.php.net/note/delete/66292/spam Del: non-english -- http://master.php.net/note/delete/66292/non-english Del: in docs -- http://master.php.net/note/delete/66292/in+docs Del: other reasons-- http://master.php.net/note/delete/66292 Reject -- http://master.php.net/note/reject/66292 Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#111595) next »