mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-15 08:28:54 +00:00
array-fill: added note and example for negative indices in php 8
This commit is contained in:
parent
51351c34a7
commit
ea3f3a185a
1 changed files with 48 additions and 9 deletions
|
@ -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>
|
||||
|
|
Loading…
Reference in a new issue