Similarities and differences between two ways to merge two arrays in PHP_PHP Tutorial

WBOY
Release: 2016-07-21 15:16:07
Original
933 people have browsed it

Especially the + operator, which means to append the right array unit (to remove duplicates) to the left array.

Copy code The code is as follows:

echo "rnFirst case rn";
$a=array(1,2,3,4,5,6);
$b=array(7,8,9);
$c=array_merge ($a,$b);
print_r($c);
$c=$a+$b;
print_r($c);
$c=$b+$a;
print_r($c);
echo "rnSecond case rn";
$a=array('a','b','c','d','e','f');
$b =array('a','x','y');
$c=array_merge ($a,$b);
print_r($c);
$c=$a+$b ;
print_r($c);
$c=$b+$a;
print_r($c);
echo "rnThird case rn";
$a=array (
1=>'a',
2=>'b',
3=>'c',
4=>'d',
5= >'e',
6=>'f');
$b=array(
1=>'a',
7=>'x',
8=>'y');
$c=array_merge ($a,$b);
print_r($c);
$c=$a+$b;
print_r( $c);
$c=$b+$a;
print_r($c);
?>

The result is as follows:
Copy code The code is as follows:

The first case
Array
(
[0] => 1
[ 1] => 2
[2] => 3
[3] => 4
[4] => 5
[5] => 6
[ 6] => 7
[7] => 8
[8] => 9
)
Array
(
[0] => 1
[1] => 2
[2] => 3
[3] => 4
[4] => 5
[5] => 6
)
Array
(
[0] => 7
[1] => 8
[2] => 9
[3] => 4
[4] => 5
[5] => 6
)
The second case
Array
(
[0] => a
[1] => b
[2] => c
[3] => d
[4] => e
[5] => f
[6] => a
[7] => x
[8] => y
)
Array
(
[0] => a
[1] => b
[2] => c
[3] => d
[4] => e
[5] => f
)
Array
(
[0] => a
[1] => x
[2] => y
[3] = > d
[4] => e
[5] => f
)
The third case
Array
(
[0] => ; a
[1] => b
[2] => c
[3] => d
[4] => e
[5] => ; f
[6] => a
[7] => => a
[2] => b
[3] => c
[4] => d
[5] => e
[6] => f
[7] => 7] => x
[8] => y
[2] => 5] => e
[6] => f
)





http://www.bkjia.com/PHPjc/325993.html

www.bkjia.com

true

http: //www.bkjia.com/PHPjc/325993.html

TechArticle
Especially the + operator, which means to append the right array unit (to remove duplicates) to the left array behind. Copy the code. The code is as follows: ?php echo "rnFirst case rn"; $a=a...

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