Skip to content

Commit 8bf3587

Browse files
authored
array-column.xml Replace array() to [], and make ex. #2 executable (#4338)
1 parent 42bb18b commit 8bf3587

File tree

1 file changed

+39
-11
lines changed

1 file changed

+39
-11
lines changed

reference/array/functions/array-column.xml

Lines changed: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -104,32 +104,34 @@
104104
<programlisting role="php">
105105
<![CDATA[
106106
<?php
107+
107108
// Array representing a possible record set returned from a database
108-
$records = array(
109-
array(
109+
$records = [
110+
[
110111
'id' => 2135,
111112
'first_name' => 'John',
112113
'last_name' => 'Doe',
113-
),
114-
array(
114+
],
115+
[
115116
'id' => 3245,
116117
'first_name' => 'Sally',
117118
'last_name' => 'Smith',
118-
),
119-
array(
119+
],
120+
[
120121
'id' => 5342,
121122
'first_name' => 'Jane',
122123
'last_name' => 'Jones',
123-
),
124-
array(
124+
],
125+
[
125126
'id' => 5623,
126127
'first_name' => 'Peter',
127128
'last_name' => 'Doe',
128-
)
129-
);
129+
]
130+
];
130131
131132
$first_names = array_column($records, 'first_name');
132133
print_r($first_names);
134+
133135
?>
134136
]]>
135137
</programlisting>
@@ -155,9 +157,34 @@ Array
155157
<programlisting role="php">
156158
<![CDATA[
157159
<?php
160+
158161
// Using the $records array from Example #1
162+
$records = [
163+
[
164+
'id' => 2135,
165+
'first_name' => 'John',
166+
'last_name' => 'Doe',
167+
],
168+
[
169+
'id' => 3245,
170+
'first_name' => 'Sally',
171+
'last_name' => 'Smith',
172+
],
173+
[
174+
'id' => 5342,
175+
'first_name' => 'Jane',
176+
'last_name' => 'Jones',
177+
],
178+
[
179+
'id' => 5623,
180+
'first_name' => 'Peter',
181+
'last_name' => 'Doe',
182+
]
183+
];
184+
159185
$last_names = array_column($records, 'last_name', 'id');
160186
print_r($last_names);
187+
161188
?>
162189
]]>
163190
</programlisting>
@@ -202,6 +229,7 @@ $users = [
202229
];
203230
204231
print_r(array_column($users, 'username'));
232+
205233
?>
206234
]]>
207235
</programlisting>
@@ -222,7 +250,7 @@ Array
222250
<example>
223251
<title>
224252
Get the column of names from the private "name" property of an object
225-
using the magic <function>__get</function> method.
253+
using the magic methods <function>__isset</function> and <function>__get</function>
226254
</title>
227255
<programlisting role="php">
228256
<![CDATA[

0 commit comments

Comments
 (0)