Share a simple method to merge arrays using the plus sign in PHP_PHP Tutorial

WBOY
Release: 2016-07-21 15:32:29
Original
940 people have browsed it

Code:

Copy code The code is as follows:

$a = array('a' = > 'a', 'b' => 'b');
$b = array('c' => 'c', 'd' => 'd');
$ c = $a + $b;
print('
'); <br>print_r($c); <br>print('
');
?>

Result:
Copy code The code is as follows:

Array
(
[a] => a
[b] => b
[c] => c
[d] => d
)

Note: There is still a difference between the plus sign and the array_merge() function, that is, when using the plus sign to merge arrays, if there are keys with the same name between the arrays, the key values ​​corresponding to the previous arrays will be retained, while the array_merge() function is just the opposite.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/322799.htmlTechArticleCode: Copy the code as follows: ?php $a = array('a' = 'a', 'b ' = 'b'); $b = array('c' = 'c', 'd' = 'd'); $c = $a + $b; print('pre'); print_r($c) ; print('/pre'); ? Result: Copy...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template