mirror of
https://github.com/php/doc-it.git
synced 2026-03-26 16:42:06 +01:00
git-svn-id: https://svn.php.net/repository/phpdoc/it/trunk@107354 c90b9560-bf6c-de11-be94-00142212c4b1
151 lines
3.9 KiB
XML
151 lines
3.9 KiB
XML
<?xml version="1.0" encoding="iso-8859-1"?>
|
|
<!-- splitted from ./it/functions/array.xml, last change in rev 1.6 -->
|
|
<!-- last change to 'list' in en/ tree in rev 1.2 -->
|
|
<!-- EN-Revision: 1.7 Maintainer: cucinato Status: ready -->
|
|
<!-- OLD-Revision: 1.173/EN.1.2 -->
|
|
<refentry id="function.list">
|
|
<refnamediv>
|
|
<refname>list</refname>
|
|
<refpurpose>
|
|
Assegna valori a delle variabili come se fossero un array
|
|
</refpurpose>
|
|
</refnamediv>
|
|
<refsect1>
|
|
<title>Descrizione</title>
|
|
<methodsynopsis>
|
|
<type>void</type><methodname>list</methodname>
|
|
<methodparam rep="repeat"><type>mixed</type><parameter>...</parameter></methodparam>
|
|
</methodsynopsis>
|
|
<para>
|
|
Come <function>array</function>, questa non è in realtà una funzione,
|
|
bensì un costrutto del linguaggio. <function>list</function> è usata per
|
|
assegnare valori ad una lista di variabili in una sola operazione.
|
|
</para>
|
|
<note>
|
|
<para>
|
|
<function>list</function> funziona solo su array numerici e si aspetta
|
|
che gli indici numerici partano da 0.
|
|
</para>
|
|
</note>
|
|
<para>
|
|
<example>
|
|
<title>esempio di <function>list</function></title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
|
|
$info = array('caffè', 'scuro', 'caffeina');
|
|
|
|
// assegna a tutte le variabili
|
|
list($bevanda, $colore, $componente) = $info;
|
|
print "Il $bevanda è $colore e la $componente lo rende speciale.\n";
|
|
|
|
// assegna solo in parte
|
|
list($bevanda, , $componente) = $info;
|
|
print "Il $bevanda ha la $componente.\n";
|
|
|
|
// oppure assegnamo solo l'ultima variabile
|
|
list( , , $componente) = $info;
|
|
print "Ho voglia di $bevanda!\n";
|
|
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
</para>
|
|
<para>
|
|
<example>
|
|
<title>Esempio di uso di <function>list</function></title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<table>
|
|
<tr>
|
|
<th>Nome dell'impiegato</th>
|
|
<th>Stipendio</th>
|
|
</tr>
|
|
|
|
<?php
|
|
|
|
$risultato = mysql_query ("SELECT id, nome, stipendio FROM impiegati",$conn);
|
|
while (list ($id, $nome, $stipendio) = mysql_fetch_row ($risultato)) {
|
|
print (" <tr>\n".
|
|
" <td><a href=\"info.php?id=$id\">$nome</a></td>\n".
|
|
" <td>$stipendio</td>\n".
|
|
" </tr>\n");
|
|
}
|
|
|
|
?>
|
|
|
|
</table>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
</para>
|
|
<warning>
|
|
<para>
|
|
<function>list</function> assegna i valori cominciando dal parametro più a
|
|
destra. Se si stanno usando variabili semplici, non ci si deve preoccupare
|
|
di questo fatto. Ma se si stanno usando array con indici di solito ci si aspetta che
|
|
l'ordine degli indici negli array sia quello scritto negli argomenti della funzione
|
|
<function>list</function>, da sinistra a destra; non è così. L'ordine è
|
|
invertito.
|
|
</para>
|
|
</warning>
|
|
<para>
|
|
<example>
|
|
<title>Utilizzo di <function>list</function> con gli indici</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
|
|
$info = array('caffè', 'nero', 'caffeina');
|
|
|
|
list($a[0], $a[1], $a[2]) = $info;
|
|
|
|
var_dump($a);
|
|
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
Restituisce il segente risultato (si noti l'ordine degli elementi rispetto
|
|
all'ordine con cui sono stati scritti nella sintassi di <function>list</function>).
|
|
<screen>
|
|
array(3) {
|
|
[2]=>
|
|
string(8) "caffeina"
|
|
[1]=>
|
|
string(4) "nero"
|
|
[0]=>
|
|
string(5) "caffè"
|
|
}
|
|
</screen>
|
|
</para>
|
|
<para>
|
|
Vedere anche <function>each</function> e <function>array</function>
|
|
e <function>extract</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:"../../../../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
|
|
-->
|