How to add arrays in php
The array function in php is very powerful, and you can even add it directly to merge arrays.
A array
$a = ['a', 'b'];
B array
$b = ['c', 'd', 'e'];
A B result
Array ( [0] => a [1] => b [2] => e )
You can see that for the same key value, the previous one will overwrite the later one.
This is different from the commonly used function array_merge:
array_merge for string key values, the latter array will overwrite the previous one
array_merge for numeric keys In terms of value, the following array will be merged with the previous one and re-indexed
Complete code
'jack', 'age' => 20]; $b = ['name' => 'tom', 'age' => 21, 'gender' => 'male']; print_r($a + $b);
Related recommendations: "PHP Tutorial"
The above is the detailed content of php array addition. For more information, please follow other related articles on the PHP Chinese website!