mirror of
https://github.com/php/doc-it.git
synced 2026-03-24 07:32:12 +01:00
git-svn-id: https://svn.php.net/repository/phpdoc/it/trunk@316416 c90b9560-bf6c-de11-be94-00142212c4b1
152 lines
4.1 KiB
XML
152 lines
4.1 KiB
XML
<?xml version="1.0" encoding="UTF-8"?>
|
|
<!-- splitted from ./it/functions/array.xml, last change in rev 1.1 -->
|
|
<!-- last change to 'array' in en/ tree in rev 1.110 -->
|
|
<!-- EN-Revision: n/a Maintainer: cucinato Status: ready -->
|
|
<!-- OLD-Revision: 1.173/EN.1.110 -->
|
|
<refentry xml:id="function.array" xmlns="http://docbook.org/ns/docbook">
|
|
<refnamediv>
|
|
<refname>array</refname>
|
|
<refpurpose>
|
|
Crea un array
|
|
</refpurpose>
|
|
</refnamediv>
|
|
<refsect1>
|
|
<title>Descrizione</title>
|
|
<methodsynopsis>
|
|
<type>array</type><methodname>array</methodname>
|
|
<methodparam choice="opt"><type>mixed</type><parameter>...</parameter></methodparam>
|
|
</methodsynopsis>
|
|
<para>
|
|
Restituisce un array contenente i parametri. Ai parametri si può dare
|
|
un indice con l'operatore <literal>=></literal>. Leggere la sezione
|
|
relativa ai <link linkend="language.types.array">tipi</link> per ulteriori
|
|
informazioni sugli array.
|
|
</para>
|
|
<para>
|
|
<note>
|
|
<para>
|
|
<function>array</function> è un costrutto del linguaggio usato per
|
|
rappresentare array letterali, e non una normale funzione.
|
|
</para>
|
|
</note>
|
|
</para>
|
|
<para>
|
|
La sintassi "indice => valori", separati da virgole, definisce indici
|
|
e valori. indice può essere di tipo string o numerico. Quando l'indice è
|
|
omesso, viene generato automaticamente un indice intero, a partire
|
|
da 0. Se l'indice è un intero, il successivo indice generato sarà
|
|
l'indice intero più grande + 1. Si noti che quando due indici
|
|
identici vengono definiti, l'ultimo sovrascrive il primo.
|
|
</para>
|
|
<para>
|
|
L'esempio seguente dimostra come creare un
|
|
array bidimensionale, come specificare le chiavi per gli array
|
|
associativi, e come modificare la serie degli indici numerici negli array
|
|
normali.
|
|
<example>
|
|
<title>Esempio di <function>array</function></title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$frutta = array (
|
|
"frutta" => array("a" => "arancia", "b" => "banana", "c" => "mela"),
|
|
"numeri" => array(1, 2, 3, 4, 5, 6),
|
|
"buche" => array("prima", 5 => "seconda", "terza")
|
|
)
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
</para>
|
|
<para>
|
|
<example>
|
|
<title>Indice automatico con <function>array</function></title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$array = array(1, 1, 1, 1, 1, 8 => 1, 4 => 1, 19, 3 => 13);
|
|
print_r($array);
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
<para>
|
|
che stamperà:
|
|
</para>
|
|
<screen role="php">
|
|
<![CDATA[
|
|
Array
|
|
(
|
|
[0] => 1
|
|
[1] => 1
|
|
[2] => 1
|
|
[3] => 13
|
|
[4] => 1
|
|
[8] => 1
|
|
[9] => 19
|
|
)
|
|
]]>
|
|
</screen>
|
|
</example>
|
|
</para>
|
|
<para>
|
|
Si noti che l'indice '3' è definito due volte, e che mantiene il valore finale 13.
|
|
L'indice 4 è definito dopo l'indice 8, e il successivo indice generato (valore 19)
|
|
è 9, dal momento che l'indice più grande era 8.
|
|
</para>
|
|
<para>
|
|
Questo esempio crea un array che parte da 1 (1-based).
|
|
<example>
|
|
<title>Indice 1-based con <function>array</function></title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$primotrimestre = array(1 => 'Gennaio', 'Febbraio', 'Marzo');
|
|
print_r($primotrimestre);
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
<para>
|
|
che stamperà:
|
|
</para>
|
|
<screen>
|
|
<![CDATA[
|
|
Array
|
|
(
|
|
[1] => Gennaio
|
|
[2] => Febbraio
|
|
[3] => Marzo
|
|
)
|
|
]]>
|
|
</screen>
|
|
</example>
|
|
</para>
|
|
<para>
|
|
Vedere anche <function>array_pad</function>,
|
|
<function>list</function>,
|
|
<link linkend="control-structures.foreach">foreach</link> e
|
|
<function>range</function>.
|
|
</para>
|
|
</refsect1>
|
|
</refentry>
|
|
|
|
<!-- Keep this comment at the end of the file
|
|
Local variables:
|
|
mode: sgml
|
|
sgml-omittag:t
|
|
sgml-shorttag:t
|
|
sgml-minimize-attributes:nil
|
|
sgml-always-quote-attributes:t
|
|
sgml-indent-step:1
|
|
sgml-indent-data:t
|
|
indent-tabs-mode:nil
|
|
sgml-parent-document:nil
|
|
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
|
|
sgml-exposed-tags:nil
|
|
sgml-local-catalogs:nil
|
|
sgml-local-ecat-files:nil
|
|
End:
|
|
vim600: syn=xml fen fdm=syntax fdl=2 si
|
|
vim: et tw=78 syn=sgml
|
|
vi: ts=1 sw=1
|
|
-->
|