array-fill: added note and example for negative indices in php 8

This commit is contained in:
overflowerror 2022-06-23 09:50:08 +02:00 committed by GitHub
parent 51351c34a7
commit ea3f3a185a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -33,12 +33,13 @@
<para>
The first index of the returned array.
</para>
<para>
If <parameter>start_index</parameter> is negative,
the first index of the returned array will be
<parameter>start_index</parameter> and the following
<para>
Up to (excluding) PHP 8, if
<parameter>start_index</parameter> is negative,
only the first index of the returned array will be
<parameter>start_index</parameter>, the following
indices will start from zero
(see <link linkend="function.array-fill.example.basic">example</link>).
(see <link linkend="function.array-fill.example.negative">example</link>).
</para>
</listitem>
</varlistentry>
@ -84,15 +85,13 @@
<refsect1 role="examples">
&reftitle.examples;
<para>
<example xml:id="function.array-fill.example.basic">
<title><function>array_fill</function> example</title>
<example xml:id="function.array-fill.example.basic">
<title>positive <parameter>start_index</parameter></title>
<programlisting role="php">
<![CDATA[
<?php
$a = array_fill(5, 6, 'banana');
$b = array_fill(-2, 4, 'pear');
print_r($a);
print_r($b);
?>
]]>
</programlisting>
@ -108,6 +107,22 @@ Array
[9] => banana
[10] => banana
)
]]>
</screen>
</example>
<example xml:id="function.array-fill.example.neagtive">
<title>negative <parameter>start_index</parameter> (PHP < 8)</title>
<programlisting role="php">
<![CDATA[
<?php
$b = array_fill(-2, 4, 'pear');
print_r($b);
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
Array
(
[-2] => pear
@ -115,6 +130,30 @@ Array
[1] => pear
[2] => pear
)
]]>
</screen>
</example>
<example xml:id="function.array-fill.example.negative8">
<title>negative <parameter>start_index</parameter> (PHP >= 8)</title>
<programlisting role="php">
<![CDATA[
<?php
$c = array_fill(-2, 5, 'apple');
print_r($c);
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
Array
(
[-2] => apple
[-1] => apple
[0] => apple
[1] => apple
[2] => apple
)
]]>
</screen>
</example>