note 86379 added to language.operators.array
| From: | cb at netalyst dot com | Date: | Wed, 15 Oct 2008 18:39:13 +0000 |
| Subject: | note 86379 added to language.operators.array | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-145390@lists.php.net to get a copy of this message | ||
The union operator did not behave as I thought it would on first glance. It implements a union (of
sorts) based on the keys of the array, not on the values.
For instance:
<?php
$a = array('one','two');
$b=array('three','four','five');
//not a union of arrays' values
echo '$a + $b : ';
print_r ($a + $b);
//a union of arrays' values
echo "array_unique(array_merge($a,$b)):";
// cribbed from http://oreilly.com/catalog/progphp/chapter/ch05.html
print_r (array_unique(array_merge($a,$b)));
?>
//output
$a + $b : Array
(
[0] => one
[1] => two
[2] => five
)
array_unique(array_merge(Array,Array)):Array
(
[0] => one
[1] => two
[2] => three
[3] => four
[4] => five
)
----
Server IP: 209.41.74.194
Probable Submitter: 66.92.171.226
----
Manual Page -- http://www.php.net/manual/en/language.operators.array.php
Edit -- https://master.php.net/note/edit/86379
Del: integrated -- https://master.php.net/note/delete/86379/integrated
Del: useless -- https://master.php.net/note/delete/86379/useless
Del: bad code -- https://master.php.net/note/delete/86379/bad+code
Del: spam -- https://master.php.net/note/delete/86379/spam
Del: non-english -- https://master.php.net/note/delete/86379/non-english
Del: in docs -- https://master.php.net/note/delete/86379/in+docs
Del: other reasons-- https://master.php.net/note/delete/86379
Reject -- https://master.php.net/note/reject/86379
Search -- https://master.php.net/manage/user-notes.php