note 92220 added to function.array-replace-recursive
| From: | kyle | Date: | Tue, 14 Jul 2009 22:05:19 +0000 |
| Subject: | note 92220 added to function.array-replace-recursive | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-158302@lists.php.net to get a copy of this message | ||
This might help out people who don't have 5.3 running:
<?
function array_join($original)
{
// Get array arguments
$arrays = func_get_args();
// Loop through arrays
foreach ($arrays as $array)
{
// Loop through array key/value pairs
foreach ($array as $key => $value)
{
// Value is an array
if (is_array($value))
{
// Traverse the array; replace or add result to original array
$original[$key] = array_join($array[$key], $original[$key]);
}
// Value is not an array
else
{
// Replace or add current value to original array
$original[$key] = $value;
}
}
}
// Return the joined array
return $original;
}
// Example
$first = array('one' => '1', 'two' => '2',
'three' => '3');
$second = array('one' => 'one', 'two' => '2',
'three' => 'three', 'four' => '4');
print_r(array_join($first, $second));
?>
Output:
Array
(
[one] => one
[two] => 2
[three] => three
[four] => 4
)
----
Server IP: 208.69.120.35
Probable Submitter: 209.164.165.25
----
Manual Page -- http://www.php.net/manual/en/function.array-replace-recursive.php
Edit -- https://master.php.net/note/edit/92220
Del: integrated -- https://master.php.net/note/delete/92220/integrated
Del: useless -- https://master.php.net/note/delete/92220/useless
Del: bad code -- https://master.php.net/note/delete/92220/bad+code
Del: spam -- https://master.php.net/note/delete/92220/spam
Del: non-english -- https://master.php.net/note/delete/92220/non-english
Del: in docs -- https://master.php.net/note/delete/92220/in+docs
Del: other reasons-- https://master.php.net/note/delete/92220
Reject -- https://master.php.net/note/reject/92220
Search -- https://master.php.net/manage/user-notes.php