August 2003
Intermediate to advanced
1104 pages
19h 27m
English
The + operator has a special meaning for arrays. It merges the elements from the array on the right into the array on the left. The keys of the arrays are important. If a key exists in the array on the left, it remains unchanged. Only elements from the array on the right with different keys merge into the array on the left. Listing 5.8 demonstrates this functionality.
<?php
//define a couple of arrays
$a = array(
0=>"Apple",
2=>"Ball");
$b = array(
1=>"Cat",
2=>"Dog");
foreach(($a + $b) as $key=>$value)
{
print("$key: $value<br>\n");
}
?>
|
Figure 5.1 shows that Listing 5.8 prints an array with three elements. The element indexed by 2 uses the value from a, not b.
Chapter 11 discusses ...