-
Notifications
You must be signed in to change notification settings - Fork 787
/
Copy patharray.xml
143 lines (138 loc) · 3.32 KB
/
array.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<?xml version="1.0" encoding="utf-8"?>
<sect1 xml:id="language.operators.array">
<title>Array Operators</title>
<titleabbrev>Array</titleabbrev>
<table>
<title>Array Operators</title>
<tgroup cols="3">
<thead>
<row>
<entry>Example</entry>
<entry>Name</entry>
<entry>Result</entry>
</row>
</thead>
<tbody>
<row>
<entry>$a + $b</entry>
<entry>Union</entry>
<entry>Union of <varname>$a</varname> and <varname>$b</varname>.</entry>
</row>
<row>
<entry>$a == $b</entry>
<entry>Equality</entry>
<entry>&true; if <varname>$a</varname> and <varname>$b</varname> have the same key/value pairs.</entry>
</row>
<row>
<entry>$a === $b</entry>
<entry>Identity</entry>
<entry>&true; if <varname>$a</varname> and <varname>$b</varname> have the same key/value pairs in the same
order and of the same types.</entry>
</row>
<row>
<entry>$a != $b</entry>
<entry>Inequality</entry>
<entry>&true; if <varname>$a</varname> is not equal to <varname>$b</varname>.</entry>
</row>
<row>
<entry>$a <> $b</entry>
<entry>Inequality</entry>
<entry>&true; if <varname>$a</varname> is not equal to <varname>$b</varname>.</entry>
</row>
<row>
<entry>$a !== $b</entry>
<entry>Non-identity</entry>
<entry>&true; if <varname>$a</varname> is not identical to <varname>$b</varname>.</entry>
</row>
</tbody>
</tgroup>
</table>
<para>
The <literal>+</literal> operator returns the right-hand array appended
to the left-hand array; for keys that exist in both arrays, the elements
from the left-hand array will be used, and the matching elements from the
right-hand array will be ignored.
</para>
<para>
<example>
<title>Array Append Operator</title>
<programlisting role="php">
<![CDATA[
<?php
$a = array("a" => "apple", "b" => "banana");
$b = array("a" => "pear", "b" => "strawberry", "c" => "cherry");
$c = $a + $b; // Union of $a and $b
echo "Union of \$a and \$b: \n";
var_dump($c);
$c = $b + $a; // Union of $b and $a
echo "Union of \$b and \$a: \n";
var_dump($c);
$a += $b; // Union of $a += $b is $a and $b
echo "Union of \$a += \$b: \n";
var_dump($a);
?>
]]>
</programlisting>
&example.outputs;
<screen role="php">
<![CDATA[
Union of $a and $b:
array(3) {
["a"]=>
string(5) "apple"
["b"]=>
string(6) "banana"
["c"]=>
string(6) "cherry"
}
Union of $b and $a:
array(3) {
["a"]=>
string(4) "pear"
["b"]=>
string(10) "strawberry"
["c"]=>
string(6) "cherry"
}
Union of $a += $b:
array(3) {
["a"]=>
string(5) "apple"
["b"]=>
string(6) "banana"
["c"]=>
string(6) "cherry"
}
]]>
</screen>
</example>
</para>
<para>
Elements of arrays are equal for the comparison if they have the
same key and value.
</para>
<para>
<example>
<title>Comparing arrays</title>
<programlisting role="php">
<![CDATA[
<?php
$a = array("apple", "banana");
$b = array(1 => "banana", "0" => "apple");
var_dump($a == $b); // bool(true)
var_dump($a === $b); // bool(false)
?>
]]>
</programlisting>
</example>
</para>
<sect2 role="seealso">
&reftitle.seealso;
<para>
<simplelist>
<member><link linkend="language.types.array">Array type</link></member>
<member><link linkend="ref.array">Array functions</link></member>
</simplelist>
</para>
</sect2>
</sect1>