note 71813 deleted from function.array-intersect by cmb
| From: | cmb@php.net | Date: | Sun, 09 Feb 2020 08:26:38 +0000 |
| Subject: | note 71813 deleted from function.array-intersect by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-214062@lists.php.net to get a copy of this message | ||
Note Submitter: aaron
----
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;
}
?>