note 112196 added to function.array-merge
| From: | JanezR. | Date: | Thu, 16 May 2013 08:38:12 +0000 |
| Subject: | note 112196 added to function.array-merge | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-194819@lists.php.net to get a copy of this message | ||
Please note that -1 is a numeric key and will be reindexed.
Less obvious numeric keys are also '-1' (becomes -1) and -1.5 (becomes -1).
'-1a', however, is not a numeric key and you could exploit the fact that '-1a'
== -1 evaluates to true in php (just a hint). But as this is not very efficient, operator + may be a
better option.
<?php
$arr = array(-1=> "-1", '-2'=> "'-2'", -3.5=>
"-3.5", '-4a'=> "'-4a'");
print_r(array(
$arr,
array_merge($arr,array()),
'-1a' == -1,
));
?>
Result:
Array
(
[0] => Array
(
[-1] => -1
[-2] => '-2'
[-3] => -3.5
[-4a] => '-4a'
)
[1] => Array
(
[0] => -1
[1] => '-2'
[2] => -3.5
[-4a] => '-4a'
)
[2] => 1
)
----
Server IP: 193.9.21.50
Probable Submitter: 77.94.130.234
----
Manual Page -- http://php.net/manual/en/function.array-merge.php
Edit -- https://master.php.net/note/edit/112196
Del: integrated -- https://master.php.net/note/delete/112196/integrated
Del: useless -- https://master.php.net/note/delete/112196/useless
Del: bad code -- https://master.php.net/note/delete/112196/bad+code
Del: spam -- https://master.php.net/note/delete/112196/spam
Del: non-english -- https://master.php.net/note/delete/112196/non-english
Del: in docs -- https://master.php.net/note/delete/112196/in+docs
Del: other reasons-- https://master.php.net/note/delete/112196
Reject -- https://master.php.net/note/reject/112196
Search -- https://master.php.net/manage/user-notes.php