8484 <programlisting role =" php" >
8585<![CDATA[
8686<?php
87- $array1 = array("color" => "red", 2, 4);
88- $array2 = array("a", "b", "color" => "green", "shape" => "trapezoid", 4);
87+
88+ $array1 = ["color" => "red", 2, 4];
89+ $array2 = ["a", "b", "color" => "green", "shape" => "trapezoid", 4];
90+
8991$result = array_merge($array1, $array2);
92+
9093print_r($result);
91- ?>
9294]]>
9395 </programlisting >
9496 &example.outputs;
@@ -114,11 +116,13 @@ Array
114116 <programlisting role =" php" >
115117<![CDATA[
116118<?php
117- $array1 = array();
118- $array2 = array(1 => "data");
119+
120+ $array1 = [];
121+ $array2 = [1 => "data"];
122+
119123$result = array_merge($array1, $array2);
124+
120125print_r($result);
121- ?>
122126]]>
123127 </programlisting >
124128 <para >
@@ -141,11 +145,13 @@ Array
141145 <programlisting role =" php" >
142146<![CDATA[
143147<?php
144- $array1 = array(0 => 'zero_a', 2 => 'two_a', 3 => 'three_a');
145- $array2 = array(1 => 'one_b', 3 => 'three_b', 4 => 'four_b');
148+
149+ $array1 = [0 => 'zero_a', 2 => 'two_a', 3 => 'three_a'];
150+ $array2 = [1 => 'one_b', 3 => 'three_b', 4 => 'four_b'];
151+
146152$result = $array1 + $array2;
153+
147154var_dump($result);
148- ?>
149155]]>
150156 </programlisting >
151157 <para >
@@ -168,31 +174,6 @@ array(5) {
168174 [4]=>
169175 string(6) "four_b"
170176}
171- ]]>
172- </screen >
173- </example >
174- </para >
175- <para >
176- <example >
177- <title ><function >array_merge</function > with non-array types</title >
178- <programlisting role =" php" >
179- <![CDATA[
180- <?php
181- $beginning = 'foo';
182- $end = array(1 => 'bar');
183- $result = array_merge((array) $beginning, (array) $end);
184- print_r($result);
185- ?>
186- ]]>
187- </programlisting >
188- &example.outputs;
189- <screen role =" php" >
190- <![CDATA[
191- Array
192- (
193- [0] => foo
194- [1] => bar
195- )
196177]]>
197178 </screen >
198179 </example >
0 commit comments