note 126978 added to function.array-replace
| From: | ricardophpyahoocombr at main dot php dot net | Date: | Fri, 08 Apr 2022 15:40:14 +0000 |
| Subject: | note 126978 added to function.array-replace | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-218140@lists.php.net to get a copy of this message | ||
Concerning the affirmation:
If you want to append array elements from the second array to the first array while not overwriting
the elements from the first array and not re-indexing, use the + array union operator
Clearing the fact (it means ...):
If the first array have a key and a value it will not be overlap by the new array. therefore if you
have an array like [1=>"alpha", 2=>"beta"] and you got a new array telling
[1=>"Alpha", 3=>"Gamma"] the final array will be [1=>"alpha",
2=>"beta", 3=>"Gamma"]. The values of first array will not be modified in
the result array.
So, if you are building a concatenation array where the values sometimes overlaps each other keys
and you must preserve values you better use array_merge instead "plus" sign
----
Server IP: 45.112.84.4
Probable Submitter: 80.90.5.135 (proxied: 2804:14c:8786:907b:473d:71d0:7e62:34d0)
----
Manual Page -- https://php.net/manual/en/function.array-replace.php
Edit -- https://main.php.net/note/edit/126978
Del: integrated -- https://main.php.net/note/delete/126978/integrated
Del: useless -- https://main.php.net/note/delete/126978/useless
Del: bad code -- https://main.php.net/note/delete/126978/bad+code
Del: spam -- https://main.php.net/note/delete/126978/spam
Del: non-english -- https://main.php.net/note/delete/126978/non-english
Del: in docs -- https://main.php.net/note/delete/126978/in+docs
Del: other reasons-- https://main.php.net/note/delete/126978
Reject -- https://main.php.net/note/reject/126978
Search -- https://main.php.net/manage/user-notes.php