note 73584 added to function.array-merge
| From: | Marce! at osu1 dot php dot net | Date: | Fri, 02 Mar 2007 12:21:36 +0000 |
| Subject: | note 73584 added to function.array-merge | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-124009@lists.php.net to get a copy of this message | ||
I have been searching for an in-place merge function, but couldn't find one. This function
merges two arrays, but leaves the order untouched.
Here it is for all others that want it:
function inplacemerge($a, $b) {
$result = array();
$i = $j = 0;
if (count($a)==0) { return $b; }
if (count($b)==0) { return $a; }
while($i < count($a) && $j < count($b)){
if ($a[$i] <= $b[$j]) {
$result[] = $a[$i];
if ($a[$i]==$b[$j]) { $j++; }
$i++;
} else {
$result[] = $b[$j];
$j++;
}
}
while ($i<count($a)){
$result[] = $a[$i];
$i++;
}
while ($j<count($b)){
$result[] = $b[$j];
$j++;
}
return $result;
}
----
Server IP: 83.137.20.120
Probable Submitter: 213.169.233.90
----
Manual Page -- http://www.php.net/manual/en/function.array-merge.php
Edit -- https://master.php.net/note/edit/73584
Del: integrated -- https://master.php.net/note/delete/73584/integrated
Del: useless -- https://master.php.net/note/delete/73584/useless
Del: bad code -- https://master.php.net/note/delete/73584/bad+code
Del: spam -- https://master.php.net/note/delete/73584/spam
Del: non-english -- https://master.php.net/note/delete/73584/non-english
Del: in docs -- https://master.php.net/note/delete/73584/in+docs
Del: other reasons-- https://master.php.net/note/delete/73584
Reject -- https://master.php.net/note/reject/73584
Search -- https://master.php.net/manage/user-notes.php