Skip to content

Commit 2e60c51

Browse files
committed
Enable WASM for book.array, and tweak examples
1 parent da15b66 commit 2e60c51

22 files changed

+95
-103
lines changed

reference/array/book.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<!-- $Revision$ -->
33

4-
<book xml:id="book.array" xmlns="http://docbook.org/ns/docbook">
4+
<book xml:id="book.array" xmlns="http://docbook.org/ns/docbook" annotations="interactive">
55
<?phpdoc extension-membership="core" ?>
66
<title>Arrays</title>
77

reference/array/functions/array-combine.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@ print_r($c);
111111
<![CDATA[
112112
Array
113113
(
114-
[green] => avocado
115-
[red] => apple
114+
[green] => avocado
115+
[red] => apple
116116
[yellow] => banana
117117
)
118118
]]>

reference/array/functions/array-diff.xml

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,15 @@ Array
103103
</example>
104104
</para>
105105

106+
<para>
107+
Two elements are considered equal if and only if
108+
<literal>(string) $elem1 === (string) $elem2</literal>. That is,
109+
when the <link linkend="language.types.string.casting">string representation</link> is the same.
110+
</para>
111+
106112
<para>
107113
<example>
108114
<title><function>array_diff</function> example with non-matching types</title>
109-
<para>
110-
Two elements are considered equal if and only if
111-
<literal>(string) $elem1 === (string) $elem2</literal>. That is,
112-
when the <link linkend="language.types.string.casting">string representation</link> is the same.
113-
</para>
114115
<programlisting role="php">
115116
<![CDATA[
116117
<?php
@@ -138,14 +139,15 @@ $filter = [new S('b'), new S('c'), new S('d')];
138139
$result = array_diff($source, $filter);
139140
140141
// $result now contains one instance of S('a');
142+
var_dump($result);
141143
?>
142144
]]>
143145
</programlisting>
144-
<para>
145-
To use an alternate comparison function, see <function>array_udiff</function>.
146-
</para>
147146
</example>
148147
</para>
148+
<para>
149+
To use an alternate comparison function, see <function>array_udiff</function>.
150+
</para>
149151
</refsect1>
150152

151153
<refsect1 role="notes">

reference/array/functions/array-fill.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,27 +146,27 @@ print_r($a);
146146
?>
147147
]]>
148148
</programlisting>
149-
&example.outputs.7;
149+
&example.outputs.8;
150150
<screen>
151151
<![CDATA[
152152
Array
153153
(
154154
[-2] => pear
155+
[-1] => pear
155156
[0] => pear
156157
[1] => pear
157-
[2] => pear
158158
)
159159
]]>
160160
</screen>
161-
&example.outputs.8;
161+
&example.outputs.7;
162162
<screen>
163163
<![CDATA[
164164
Array
165165
(
166166
[-2] => pear
167-
[-1] => pear
168167
[0] => pear
169168
[1] => pear
169+
[2] => pear
170170
)
171171
]]>
172172
</screen>

reference/array/functions/array-is-list.xml

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,22 +50,21 @@
5050
<programlisting role="php">
5151
<![CDATA[
5252
<?php
53-
54-
array_is_list([]); // true
55-
array_is_list(['apple', 2, 3]); // true
56-
array_is_list([0 => 'apple', 'orange']); // true
53+
var_dump(array_is_list([])); // true
54+
var_dump(array_is_list(['apple', 2, 3])); // true
55+
var_dump(array_is_list([0 => 'apple', 'orange'])); // true
5756
5857
// The array does not start at 0
59-
array_is_list([1 => 'apple', 'orange']); // false
58+
var_dump(array_is_list([1 => 'apple', 'orange'])); // false
6059
6160
// The keys are not in the correct order
62-
array_is_list([1 => 'apple', 0 => 'orange']); // false
61+
var_dump(array_is_list([1 => 'apple', 0 => 'orange'])); // false
6362
6463
// Non-integer keys
65-
array_is_list([0 => 'apple', 'foo' => 'bar']); // false
64+
var_dump(array_is_list([0 => 'apple', 'foo' => 'bar'])); // false
6665
6766
// Non-consecutive keys
68-
array_is_list([0 => 'apple', 2 => 'bar']); // false
67+
var_dump(array_is_list([0 => 'apple', 2 => 'bar'])); // false
6968
?>
7069
]]>
7170
</programlisting>

reference/array/functions/array-map.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ print_r(array_map(fn($value): int => $value * 2, range(1, 5)));
155155
?>
156156
]]>
157157
</programlisting>
158+
&example.outputs;
158159
<screen>
159160
<![CDATA[
160161
Array

reference/array/functions/array-merge.xml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ Array
117117
$array1 = array();
118118
$array2 = array(1 => "data");
119119
$result = array_merge($array1, $array2);
120+
print_r($result);
120121
?>
121122
]]>
122123
</programlisting>
@@ -186,12 +187,12 @@ print_r($result);
186187
</programlisting>
187188
&example.outputs;
188189
<screen role="php">
189-
<![CDATA[
190-
Array
191-
(
192-
[0] => foo
193-
[1] => bar
194-
)
190+
<![CDATA[
191+
Array
192+
(
193+
[0] => foo
194+
[1] => bar
195+
)
195196
]]>
196197
</screen>
197198
</example>

reference/array/functions/array-multisort.xml

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -234,18 +234,6 @@ volume | edition
234234
The data as an array, called <varname>data</varname>. This would usually,
235235
for example, be obtained by looping with <function>mysqli_fetch_assoc</function>.
236236
</para>
237-
<programlisting role="php">
238-
<![CDATA[
239-
<?php
240-
$data[] = array('volume' => 67, 'edition' => 2);
241-
$data[] = array('volume' => 86, 'edition' => 1);
242-
$data[] = array('volume' => 85, 'edition' => 6);
243-
$data[] = array('volume' => 98, 'edition' => 2);
244-
$data[] = array('volume' => 86, 'edition' => 6);
245-
$data[] = array('volume' => 67, 'edition' => 7);
246-
?>
247-
]]>
248-
</programlisting>
249237
<para>
250238
In this example, we will order by <varname>volume</varname> descending,
251239
<varname>edition</varname> ascending.
@@ -258,19 +246,34 @@ $data[] = array('volume' => 67, 'edition' => 7);
258246
<programlisting role="php">
259247
<![CDATA[
260248
<?php
249+
// The data as created by looping over mysqli_fetch_assoc:
250+
$data[] = array('volume' => 67, 'edition' => 2);
251+
$data[] = array('volume' => 86, 'edition' => 1);
252+
$data[] = array('volume' => 85, 'edition' => 6);
253+
$data[] = array('volume' => 98, 'edition' => 2);
254+
$data[] = array('volume' => 86, 'edition' => 6);
255+
$data[] = array('volume' => 67, 'edition' => 7);
256+
261257
// Obtain a list of columns
262258
foreach ($data as $key => $row) {
263259
$volume[$key] = $row['volume'];
264260
$edition[$key] = $row['edition'];
265261
}
266262
267-
// you can use array_column() instead of the above code
263+
// You can use array_column() instead of the above code
268264
$volume = array_column($data, 'volume');
269265
$edition = array_column($data, 'edition');
270266
271267
// Sort the data with volume descending, edition ascending
272268
// Add $data as the last parameter, to sort by the common key
273269
array_multisort($volume, SORT_DESC, $edition, SORT_ASC, $data);
270+
271+
// Loop over the data and output the sorted values for each column
272+
echo 'volume | edition', PHP_EOL;
273+
echo '-------+--------', PHP_EOL;
274+
for ($i = 0; $i < count($data); $i++) {
275+
printf("%6d | %7d\n", $volume[$i], $edition[$i]);
276+
}
274277
?>
275278
]]>
276279
</programlisting>

reference/array/functions/array-pad.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,15 @@ $input = array(12, 10, 9);
110110
111111
$result = array_pad($input, 5, 0);
112112
// result is array(12, 10, 9, 0, 0)
113+
echo join(', ', $result), PHP_EOL;
113114
114115
$result = array_pad($input, -7, -1);
115116
// result is array(-1, -1, -1, -1, 12, 10, 9)
117+
echo join(', ', $result), PHP_EOL;
116118
117119
$result = array_pad($input, 2, "noop");
118120
// not padded
121+
echo join(', ', $result), PHP_EOL;
119122
?>
120123
]]>
121124
</programlisting>

reference/array/functions/array-search.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,10 @@
8585
$array = array(0 => 'blue', 1 => 'red', 2 => 'green', 3 => 'red');
8686
8787
$key = array_search('green', $array); // $key = 2;
88+
print_r($key);
89+
8890
$key = array_search('red', $array); // $key = 1;
91+
print_r($key);
8992
?>
9093
]]>
9194
</programlisting>

0 commit comments

Comments
 (0)