This article mainly introduces you to the PHP array addition operation and the difference with array_merge. The article introduces it in detail through examples. Friends who are interested can refer to it. If necessary, follow the editor to learn together. Study it.
Found the problem
I saw a piece of code today, it was written like this, I feel unfamiliar, paste it below to have a look:
<?php $array_one = [ 内容 ]; $array_two = [ 内容 ]; //关键的在这里 $array_result = $array_one + $array_two; echo "<pre/>"; print_r($array_result); ?>
What I feel is strange is that the array $array_one
and the array $array_two
are directly added together. I used to Array merging operations are performed according to the array_merge()
function. I have never used the above method to perform operations directly.
The analysis is as follows
The following is a brief explanation of the difference between this method and the array_merge()
function What's the difference. When using the " " sign to perform operations directly, the array before the " " sign is used as the base array. If the array after the " " sign is completely consistent with the previous array (complete consistency means the key is the same and the value is the same ), the data in the previous array shall prevail. If array_merge()
is used, it is the opposite, based on the following array.
The above is the entire content of this article, I hope it will be helpful to everyone's study.
Related recommendations:
phpDetailed explanation of the method of custom function to count the length of Chinese strings
phpHow to implement the method of modifying the array key name
How to implement the infinite classification function in PHP
The above is the detailed content of PHP array addition operation and the difference from array_merge. For more information, please follow other related articles on the PHP Chinese website!