[DOC-CVS] [doc-en] master: Enable WASM for book.array, and tweak examples
[email protected] (Derick Rethans)
| Newsgroups | php.doc.cvs |
|---|---|
| Message-ID | <[email protected]> |
Author: Derick Rethans (derickr)
Date: 2025-05-07T10:52:58+01:00
Commit: https://github.com/php/doc-en/commit/2e60c5134e7a847c99f81eb3f7ecee1f5efeeace
Raw diff: https://github.com/php/doc-en/commit/2e60c5134e7a847c99f81eb3f7ecee1f5efeeace.diff
Enable WASM for book.array, and tweak examples
Changed paths:
M reference/array/book.xml
M reference/array/functions/array-combine.xml
M reference/array/functions/array-diff.xml
M reference/array/functions/array-fill.xml
M reference/array/functions/array-is-list.xml
M reference/array/functions/array-map.xml
M reference/array/functions/array-merge.xml
M reference/array/functions/array-multisort.xml
M reference/array/functions/array-pad.xml
M reference/array/functions/array-search.xml
M reference/array/functions/array-splice.xml
M reference/array/functions/array-udiff-uassoc.xml
M reference/array/functions/array.xml
M reference/array/functions/count.xml
M reference/array/functions/current.xml
M reference/array/functions/each.xml
M reference/array/functions/in-array.xml
M reference/array/functions/list.xml
M reference/array/functions/next.xml
M reference/array/functions/prev.xml
M reference/array/functions/usort.xml
M reference/array/versions.xml
Diff:
diff --git a/reference/array/book.xml b/reference/array/book.xml
index 836fc23559bc..14f0dbe6d0ca 100644
--- a/reference/array/book.xml
+++ b/reference/array/book.xml
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
-<book xml:id="book.array" xmlns="http://docbook.org/ns/docbook">
+<book xml:id="book.array" xmlns="http://docbook.org/ns/docbook" annotations="interactive">
<?phpdoc extension-membership="core" ?>
<title>Arrays</title>
diff --git a/reference/array/functions/array-combine.xml b/reference/array/functions/array-combine.xml
index c665197087c9..7efdb6847c84 100644
--- a/reference/array/functions/array-combine.xml
+++ b/reference/array/functions/array-combine.xml
@@ -111,8 +111,8 @@ print_r($c);
<![CDATA[
Array
(
- [green] => avocado
- [red] => apple
+ [green] => avocado
+ [red] => apple
[yellow] => banana
)
]]>
diff --git a/reference/array/functions/array-diff.xml b/reference/array/functions/array-diff.xml
index 4bba23650105..cfa386b50dcc 100644
--- a/reference/array/functions/array-diff.xml
+++ b/reference/array/functions/array-diff.xml
@@ -103,14 +103,15 @@ Array
</example>
</para>
+ <para>
+ Two elements are considered equal if and only if
+ <literal>(string) $elem1 === (string) $elem2</literal>. That is,
+ when the <link linkend="language.types.string.casting">string representation</link> is the same.
+ </para>
+
<para>
<example>
<title><function>array_diff</function> example with non-matching types</title>
- <para>
- Two elements are considered equal if and only if
- <literal>(string) $elem1 === (string) $elem2</literal>. That is,
- when the <link linkend="language.types.string.casting">string representation</link> is the same.
- </para>
<programlisting role="php">
<![CDATA[
<?php
@@ -138,14 +139,15 @@ $filter = [new S('b'), new S('c'), new S('d')];
$result = array_diff($source, $filter);
// $result now contains one instance of S('a');
+var_dump($result);
?>
]]>
</programlisting>
- <para>
- To use an alternate comparison function, see <function>array_udiff</function>.
- </para>
</example>
</para>
+ <para>
+ To use an alternate comparison function, see <function>array_udiff</function>.
+ </para>
</refsect1>
<refsect1 role="notes">
diff --git a/reference/array/functions/array-fill.xml b/reference/array/functions/array-fill.xml
index 8fff9d254355..8c8e822eea0a 100644
--- a/reference/array/functions/array-fill.xml
+++ b/reference/array/functions/array-fill.xml
@@ -146,27 +146,27 @@ print_r($a);
?>
]]>
</programlisting>
- &example.outputs.7;
+ &example.outputs.8;
<screen>
<![CDATA[
Array
(
[-2] => pear
+ [-1] => pear
[0] => pear
[1] => pear
- [2] => pear
)
]]>
</screen>
- &example.outputs.8;
+ &example.outputs.7;
<screen>
<![CDATA[
Array
(
[-2] => pear
- [-1] => pear
[0] => pear
[1] => pear
+ [2] => pear
)
]]>
</screen>
diff --git a/reference/array/functions/array-is-list.xml b/reference/array/functions/array-is-list.xml
index 979521e2e4d2..db68316f945d 100644
--- a/reference/array/functions/array-is-list.xml
+++ b/reference/array/functions/array-is-list.xml
@@ -50,22 +50,21 @@
<programlisting role="php">
<![CDATA[
<?php
-
-array_is_list([]); // true
-array_is_list(['apple', 2, 3]); // true
-array_is_list([0 => 'apple', 'orange']); // true
+var_dump(array_is_list([])); // true
+var_dump(array_is_list(['apple', 2, 3])); // true
+var_dump(array_is_list([0 => 'apple', 'orange'])); // true
// The array does not start at 0
-array_is_list([1 => 'apple', 'orange']); // false
+var_dump(array_is_list([1 => 'apple', 'orange'])); // false
// The keys are not in the correct order
-array_is_list([1 => 'apple', 0 => 'orange']); // false
+var_dump(array_is_list([1 => 'apple', 0 => 'orange'])); // false
// Non-integer keys
-array_is_list([0 => 'apple', 'foo' => 'bar']); // false
+var_dump(array_is_list([0 => 'apple', 'foo' => 'bar'])); // false
// Non-consecutive keys
-array_is_list([0 => 'apple', 2 => 'bar']); // false
+var_dump(array_is_list([0 => 'apple', 2 => 'bar'])); // false
?>
]]>
</programlisting>
diff --git a/reference/array/functions/array-map.xml b/reference/array/functions/array-map.xml
index b7a4558aba69..fc2eea2421cd 100644
--- a/reference/array/functions/array-map.xml
+++ b/reference/array/functions/array-map.xml
@@ -155,6 +155,7 @@ print_r(array_map(fn($value): int => $value * 2, range(1, 5)));
?>
]]>
</programlisting>
+ &example.outputs;
<screen>
<![CDATA[
Array
diff --git a/reference/array/functions/array-merge.xml b/reference/array/functions/array-merge.xml
index 2fd4020aa690..b9e3da1c0b37 100644
--- a/reference/array/functions/array-merge.xml
+++ b/reference/array/functions/array-merge.xml
@@ -117,6 +117,7 @@ Array
$array1 = array();
$array2 = array(1 => "data");
$result = array_merge($array1, $array2);
+print_r($result);
?>
]]>
</programlisting>
@@ -186,12 +187,12 @@ print_r($result);
</programlisting>
&example.outputs;
<screen role="php">
- <![CDATA[
- Array
- (
- [0] => foo
- [1] => bar
- )
+<![CDATA[
+Array
+(
+ [0] => foo
+ [1] => bar
+)
]]>
</screen>
</example>
diff --git a/reference/array/functions/array-multisort.xml b/reference/array/functions/array-multisort.xml
index ea717e3db44c..e45e7cc51b83 100644
--- a/reference/array/functions/array-multisort.xml
+++ b/reference/array/functions/array-multisort.xml
@@ -234,18 +234,6 @@ volume | edition
The data as an array, called <varname>data</varname>. This would usually,
for example, be obtained by looping with <function>mysqli_fetch_assoc</function>.
</para>
- <programlisting role="php">
-<![CDATA[
-<?php
-$data[] = array('volume' => 67, 'edition' => 2);
-$data[] = array('volume' => 86, 'edition' => 1);
-$data[] = array('volume' => 85, 'edition' => 6);
-$data[] = array('volume' => 98, 'edition' => 2);
-$data[] = array('volume' => 86, 'edition' => 6);
-$data[] = array('volume' => 67, 'edition' => 7);
-?>
-]]>
- </programlisting>
<para>
In this example, we will order by <varname>volume</varname> descending,
<varname>edition</varname> ascending.
@@ -258,19 +246,34 @@ $data[] = array('volume' => 67, 'edition' => 7);
<programlisting role="php">
<![CDATA[
<?php
+// The data as created by looping over mysqli_fetch_assoc:
+$data[] = array('volume' => 67, 'edition' => 2);
+$data[] = array('volume' => 86, 'edition' => 1);
+$data[] = array('volume' => 85, 'edition' => 6);
+$data[] = array('volume' => 98, 'edition' => 2);
+$data[] = array('volume' => 86, 'edition' => 6);
+$data[] = array('volume' => 67, 'edition' => 7);
+
// Obtain a list of columns
foreach ($data as $key => $row) {
$volume[$key] = $row['volume'];
$edition[$key] = $row['edition'];
}
-// you can use array_column() instead of the above code
+// You can use array_column() instead of the above code
$volume = array_column($data, 'volume');
$edition = array_column($data, 'edition');
// Sort the data with volume descending, edition ascending
// Add $data as the last parameter, to sort by the common key
array_multisort($volume, SORT_DESC, $edition, SORT_ASC, $data);
+
+// Loop over the data and output the sorted values for each column
+echo 'volume | edition', PHP_EOL;
+echo '-------+--------', PHP_EOL;
+for ($i = 0; $i < count($data); $i++) {
+ printf("%6d | %7d\n", $volume[$i], $edition[$i]);
+}
?>
]]>
</programlisting>
diff --git a/reference/array/functions/array-pad.xml b/reference/array/functions/array-pad.xml
index 6d3176e61c85..9927b73da4e3 100644
--- a/reference/array/functions/array-pad.xml
+++ b/reference/array/functions/array-pad.xml
@@ -110,12 +110,15 @@ $input = array(12, 10, 9);
$result = array_pad($input, 5, 0);
// result is array(12, 10, 9, 0, 0)
+echo join(', ', $result), PHP_EOL;
$result = array_pad($input, -7, -1);
// result is array(-1, -1, -1, -1, 12, 10, 9)
+echo join(', ', $result), PHP_EOL;
$result = array_pad($input, 2, "noop");
// not padded
+echo join(', ', $result), PHP_EOL;
?>
]]>
</programlisting>
diff --git a/reference/array/functions/array-search.xml b/reference/array/functions/array-search.xml
index 564bdb44639e..e71dbc736eb8 100644
--- a/reference/array/functions/array-search.xml
+++ b/reference/array/functions/array-search.xml
@@ -85,7 +85,10 @@
$array = array(0 => 'blue', 1 => 'red', 2 => 'green', 3 => 'red');
$key = array_search('green', $array); // $key = 2;
+print_r($key);
+
$key = array_search('red', $array); // $key = 1;
+print_r($key);
?>
]]>
</programlisting>
diff --git a/reference/array/functions/array-splice.xml b/reference/array/functions/array-splice.xml
index 318a854d7f75..701e77f003b4 100644
--- a/reference/array/functions/array-splice.xml
+++ b/reference/array/functions/array-splice.xml
@@ -216,7 +216,7 @@ array(5) {
<para>
The following statements are equivalent:
</para>
- <programlisting role="php">
+ <programlisting role="php" annotations="non-interactive">
<![CDATA[
<?php
diff --git a/reference/array/functions/array-udiff-uassoc.xml b/reference/array/functions/array-udiff-uassoc.xml
index eb017b9c02f0..9f0c4ee761e9 100644
--- a/reference/array/functions/array-udiff-uassoc.xml
+++ b/reference/array/functions/array-udiff-uassoc.xml
@@ -114,17 +114,17 @@ Array
(
[0.1] => cr Object
(
- [priv_member:private] => 9
+ [priv_member:cr:private] => 9
)
[0.5] => cr Object
(
- [priv_member:private] => 12
+ [priv_member:cr:private] => 12
)
[0] => cr Object
(
- [priv_member:private] => 23
+ [priv_member:cr:private] => 23
)
)
]]>
diff --git a/reference/array/functions/array.xml b/reference/array/functions/array.xml
index 3f0f4ab1ccf2..1d60a26f0728 100644
--- a/reference/array/functions/array.xml
+++ b/reference/array/functions/array.xml
@@ -67,6 +67,7 @@ $fruits = array (
"numbers" => array(1, 2, 3, 4, 5, 6),
"holes" => array("first", 5 => "second", "third")
);
+print_r($fruits);
?>
]]>
</programlisting>
@@ -78,7 +79,7 @@ $fruits = array (
<programlisting role="php">
<![CDATA[
<?php
-$array = array(1, 1, 1, 1, 1, 8 => 1, 4 => 1, 19, 3 => 13);
+$array = array(1, 1, 1, 1, 1, 8 => 1, 4 => 1, 19, 3 => 13);
print_r($array);
?>
]]>
@@ -112,8 +113,8 @@ Array
<programlisting role="php">
<![CDATA[
<?php
-$firstquarter = array(1 => 'January', 'February', 'March');
-print_r($firstquarter);
+$firstQuarter = array(1 => 'January', 'February', 'March');
+print_r($firstQuarter);
?>
]]>
</programlisting>
@@ -138,10 +139,8 @@ Array
<programlisting role="php">
<![CDATA[
<?php
-
$foo = array('bar' => 'baz');
echo "Hello {$foo['bar']}!"; // Hello baz!
-
?>
]]>
</programlisting>
diff --git a/reference/array/functions/count.xml b/reference/array/functions/count.xml
index 6cc9c0052df4..ea756d0809a2 100644
--- a/reference/array/functions/count.xml
+++ b/reference/array/functions/count.xml
@@ -130,7 +130,7 @@ int(3)
<para>
<example xml:id="count.example.badexample">
<title><function>count</function> non Countable|array example (bad example - don't do this)</title>
- <programlisting role="php">
+ <programlisting role="php" annotations="non-interactive">
<![CDATA[
<?php
$b[0] = 7;
@@ -148,26 +148,6 @@ var_dump(count(false));
<screen role="php">
<![CDATA[
int(3)
-int(0)
-int(1)
-]]>
- </screen>
- &example.outputs.72;
- <screen role="php">
-<![CDATA[
-int(3)
-
-Warning: count(): Parameter must be an array or an object that implements Countable in … on line 12
-int(0)
-
-Warning: count(): Parameter must be an array or an object that implements Countable in … on line 14
-int(1)
-]]>
- </screen>
- &example.outputs.8;
- <screen role="php">
-<![CDATA[
-int(3)
Fatal error: Uncaught TypeError: count(): Argument #1 ($var) must be of type Countable .. on line 12
]]>
diff --git a/reference/array/functions/current.xml b/reference/array/functions/current.xml
index 0bec655358c4..e09dc9d333cc 100644
--- a/reference/array/functions/current.xml
+++ b/reference/array/functions/current.xml
@@ -70,12 +70,12 @@
<![CDATA[
<?php
$transport = array('foot', 'bike', 'car', 'plane');
-$mode = current($transport); // $mode = 'foot';
-$mode = next($transport); // $mode = 'bike';
-$mode = current($transport); // $mode = 'bike';
-$mode = prev($transport); // $mode = 'foot';
-$mode = end($transport); // $mode = 'plane';
-$mode = current($transport); // $mode = 'plane';
+echo $mode = current($transport), PHP_EOL; // $mode = 'foot';
+echo $mode = next($transport), PHP_EOL; // $mode = 'bike';
+echo $mode = current($transport), PHP_EOL; // $mode = 'bike';
+echo $mode = prev($transport), PHP_EOL; // $mode = 'foot';
+echo $mode = end($transport), PHP_EOL; // $mode = 'plane';
+echo $mode = current($transport), PHP_EOL; // $mode = 'plane';
$arr = array();
var_dump(current($arr)); // bool(false)
diff --git a/reference/array/functions/each.xml b/reference/array/functions/each.xml
index 9f0eeacd7192..0209087b47e5 100644
--- a/reference/array/functions/each.xml
+++ b/reference/array/functions/each.xml
@@ -65,7 +65,7 @@
<para>
<example>
<title><function>each</function> examples</title>
- <programlisting role="php">
+ <programlisting role="php" annotations="non-interactive">
<![CDATA[
<?php
$foo = array("bob", "fred", "jussi", "jouni", "egon", "marliese");
@@ -93,7 +93,7 @@ Array
</para>
<para>
<informalexample>
- <programlisting role="php">
+ <programlisting role="php" annotations="non-interactive">
<![CDATA[
<?php
$foo = array("Robert" => "Bob", "Seppo" => "Sepi");
@@ -125,7 +125,7 @@ Array
example:
<example>
<title>Traversing an array with <function>each</function></title>
- <programlisting role="php">
+ <programlisting role="php" annotations="non-interactive">
<![CDATA[
<?php
$fruit = array('a' => 'apple', 'b' => 'banana', 'c' => 'cranberry');
diff --git a/reference/array/functions/in-array.xml b/reference/array/functions/in-array.xml
index 936159ebd80a..8b2da4cc4c40 100644
--- a/reference/array/functions/in-array.xml
+++ b/reference/array/functions/in-array.xml
@@ -153,8 +153,8 @@ if (in_array('o', $a)) {
&example.outputs;
<screen>
<![CDATA[
- 'ph' was found
- 'o' was found
+'ph' was found
+'o' was found
]]>
</screen>
</example>
diff --git a/reference/array/functions/list.xml b/reference/array/functions/list.xml
index 1ccb5a15fc09..38265af3af9d 100644
--- a/reference/array/functions/list.xml
+++ b/reference/array/functions/list.xml
@@ -126,7 +126,7 @@ var_dump($bar); // NULL
<para>
<example>
<title>An example use of <function>list</function></title>
- <programlisting role="php">
+ <programlisting role="php" annotations="non-interactive">
<![CDATA[
<?php
$result = $pdo->query("SELECT id, name FROM employees");
@@ -152,6 +152,7 @@ var_dump($a, $b, $c);
?>
]]>
</programlisting>
+ &example.outputs;
<screen>
<![CDATA[
int(1)
@@ -161,13 +162,13 @@ int(3)
</screen>
</example>
</para>
+ <para>
+ The order in which the indices of the array to be consumed by
+ <function>list</function> are defined is irrelevant.
+ </para>
<para>
<example>
<title><function>list</function> and order of index definitions</title>
- <simpara>
- The order in which the indices of the array to be consumed by
- <function>list</function> are defined is irrelevant.
- </simpara>
<programlisting role="php">
<![CDATA[
<?php
diff --git a/reference/array/functions/next.xml b/reference/array/functions/next.xml
index 69ce0aa57fcc..8a4e6910e914 100644
--- a/reference/array/functions/next.xml
+++ b/reference/array/functions/next.xml
@@ -71,11 +71,11 @@
<![CDATA[
<?php
$transport = array('foot', 'bike', 'car', 'plane');
-$mode = current($transport); // $mode = 'foot';
-$mode = next($transport); // $mode = 'bike';
-$mode = next($transport); // $mode = 'car';
-$mode = prev($transport); // $mode = 'bike';
-$mode = end($transport); // $mode = 'plane';
+echo $mode = current($transport), PHP_EOL; // $mode = 'foot';
+echo $mode = next($transport), PHP_EOL; // $mode = 'bike';
+echo $mode = next($transport), PHP_EOL; // $mode = 'car';
+echo $mode = prev($transport), PHP_EOL; // $mode = 'bike';
+echo $mode = end($transport), PHP_EOL; // $mode = 'plane';
?>
]]>
</programlisting>
diff --git a/reference/array/functions/prev.xml b/reference/array/functions/prev.xml
index 6c0469a22057..794bd8a69061 100644
--- a/reference/array/functions/prev.xml
+++ b/reference/array/functions/prev.xml
@@ -70,11 +70,11 @@
<![CDATA[
<?php
$transport = array('foot', 'bike', 'car', 'plane');
-$mode = current($transport); // $mode = 'foot';
-$mode = next($transport); // $mode = 'bike';
-$mode = next($transport); // $mode = 'car';
-$mode = prev($transport); // $mode = 'bike';
-$mode = end($transport); // $mode = 'plane';
+echo $mode = current($transport), PHP_EOL; // $mode = 'foot';
+echo $mode = next($transport), PHP_EOL; // $mode = 'bike';
+echo $mode = next($transport), PHP_EOL; // $mode = 'car';
+echo $mode = prev($transport), PHP_EOL; // $mode = 'bike';
+echo $mode = end($transport), PHP_EOL; // $mode = 'plane';
?>
]]>
</programlisting>
diff --git a/reference/array/functions/usort.xml b/reference/array/functions/usort.xml
index 5154e69ad1e5..91c96a0bb1b6 100644
--- a/reference/array/functions/usort.xml
+++ b/reference/array/functions/usort.xml
@@ -158,10 +158,6 @@ foreach ($fruits as $key => $value) {
?>
]]>
</programlisting>
- <para>
- When sorting a multi-dimensional array, <varname>$a</varname> and
- <varname>$b</varname> contain references to the first index of the array.
- </para>
&example.outputs;
<screen>
<![CDATA[
@@ -170,6 +166,10 @@ $fruits[1]: grapes
$fruits[2]: lemons
]]>
</screen>
+ <para>
+ When sorting a multi-dimensional array, <varname>$a</varname> and
+ <varname>$b</varname> contain references to the first index of the array.
+ </para>
</example>
</para>
<para>
diff --git a/reference/array/versions.xml b/reference/array/versions.xml
index 82064ec2e97e..39a5e36c7732 100644
--- a/reference/array/versions.xml
+++ b/reference/array/versions.xml
@@ -67,7 +67,7 @@
<function name='compact' from='PHP 4, PHP 5, PHP 7, PHP 8'/>
<function name='count' from='PHP 4, PHP 5, PHP 7, PHP 8'/>
<function name='current' from='PHP 4, PHP 5, PHP 7, PHP 8'/>
- <function name='each' from='PHP 4, PHP 5, PHP 7' deprecated='PHP 7.2.0'/>
+ <function name='each' from='PHP 4, PHP 5, PHP 7' deprecated='PHP 7.2.0' removed='PHP 8'/>
<function name='end' from='PHP 4, PHP 5, PHP 7, PHP 8'/>
<function name='extract' from='PHP 4, PHP 5, PHP 7, PHP 8'/>
<function name='in_array' from='PHP 4, PHP 5, PHP 7, PHP 8'/>