Adding details and examples to indexes behaviors.

git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@36739 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
Damien Seguy 2000-11-29 19:47:41 +00:00
parent 25094f9009
commit 6d6555ccc9

View file

@ -49,6 +49,14 @@
</para>
</note>
</para>
<para>
Syntax "index =&gt; values", separated by commas, define index
and values. index may be of type string or numeric. When index is
omitted, a integer index is automatically generated, starting
at 0. If index is an integer, next generated index will
be the biggest integer index + 1. Note that when two identical
index are defined, the last overwrite the first.
</para>
<para>
The following example demonstrates how to create a
two-dimensional array, how to specify keys for associative
@ -65,6 +73,50 @@ $fruits = array (
</programlisting>
</example>
</para>
<para>
<example>
<title>Automatic index with <function>Array</function></title>
<programlisting role="php">
$array = array( 1, 1, 1, 1, 1, 8=>1, 4=>1, 19, 3=>13);
print_r($array);
</programlisting>
</example>
which will display :
<informalexample>
Array
(
[0] => 1
[1] => 1
[2] => 1
[3] => 13
[4] => 1
[8] => 1
[9] => 19
)
</informalexample>
Note that index '3' is defined twice, and keep its final value of 13.
Index 4 is defined after index 8, and next generated index (value 19)
is 9, since biggest index was 8.
</para>
<para>
This example creates a 1-based array.
<example>
<title>1-based index with <function>Array</function></title>
<programlisting role="php">
$firstquarter = array(1 => 'January', 'February', 'March');
print_r($firstquarter);
</programlisting>
</example>
which will display :
<informalexample>
Array
(
[1] => 'January'
[2] => 'February'
[3] => 'March'
)
</informalexample>
</para>
<para>
See also: <function>list</function>.
</para>