note 71813 added to function.array-intersect
| From: | aaron at osu1 dot php dot net | Date: | Sun, 17 Dec 2006 17:36:15 +0000 |
| Subject: | note 71813 added to function.array-intersect | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-120669@lists.php.net to get a copy of this message | ||
this one will work with associative arrays. also an overwrite function to only replace those
elements in the first array.
<?php
function array_union()
{
if (func_num_args() < 2) { return; }
$arrays = func_get_args();
$outputArray = array_shift($arrays);
$remaining = count($arrays);
for ($i=0; $i<$remaining; $i++)
{
$nextArray = $arrays[$i];
foreach ($nextArray as $key=>$value)
{
$outputArray[$key] = $value;
}
}
return $outputArray;
}
function array_overwrite()
{
if (func_num_args() < 2) { return; }
$arrays = func_get_args();
$outputArray = array_shift($arrays);
$remaining = count($arrays);
for ($i=0; $i<$remaining; $i++)
{
$nextArray = $arrays[$i];
foreach ($nextArray as $key=>$value)
{
if (array_key_exists($key, $outputArray)) { $outputArray[$key] = $value; }
}
}
return $outputArray;
}
?>
----
Server IP: 66.163.161.117
Probable Submitter: 62.51.26.112
----
Manual Page -- http://www.php.net/manual/en/function.array-intersect.php
Edit -- https://master.php.net/note/edit/71813
Del: integrated -- https://master.php.net/note/delete/71813/integrated
Del: useless -- https://master.php.net/note/delete/71813/useless
Del: bad code -- https://master.php.net/note/delete/71813/bad+code
Del: spam -- https://master.php.net/note/delete/71813/spam
Del: non-english -- https://master.php.net/note/delete/71813/non-english
Del: in docs -- https://master.php.net/note/delete/71813/in+docs
Del: other reasons-- https://master.php.net/note/delete/71813
Reject -- https://master.php.net/note/reject/71813
Search -- https://master.php.net/manage/user-notes.php