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
153 lines
5.0 KiB
XML
153 lines
5.0 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-walk' in en/ tree in rev 1.2 -->
|
|
<!-- EN-Revision: n/a Maintainer: cucinato Status: ready -->
|
|
<!-- OLD-Revision: 1.173/EN.1.2 -->
|
|
<refentry xml:id="function.array-walk" xmlns="http://docbook.org/ns/docbook">
|
|
<refnamediv>
|
|
<refname>array_walk</refname>
|
|
<refpurpose>
|
|
Esegue una funzione su ogni elemento dell'array
|
|
</refpurpose>
|
|
</refnamediv>
|
|
<refsect1>
|
|
<title>Descrizione</title>
|
|
<methodsynopsis>
|
|
<type>bool</type><methodname>array_walk</methodname>
|
|
<methodparam><type>array</type><parameter>&array</parameter></methodparam>
|
|
<methodparam><type>callback</type><parameter>funzione</parameter></methodparam>
|
|
<methodparam choice="opt"><type>mixed</type><parameter>datiutente</parameter></methodparam>
|
|
</methodsynopsis>
|
|
<simpara>
|
|
&return.success;
|
|
</simpara>
|
|
<simpara>
|
|
Esegue la funzione definita dall'utente identificata da <parameter>funzione</parameter>
|
|
su ogni elemento di <parameter>array</parameter>. Normalmente
|
|
<parameter>funzione</parameter> accetta due parametri.
|
|
Il valore del parametro <parameter>array</parameter> viene passato per primo,
|
|
la chiave/indice per secondo. Se il parametro <parameter>datiutente</parameter>
|
|
è specificato, verrà passato come terzo parametro alla
|
|
<parameter>funzione</parameter> callback.
|
|
</simpara>
|
|
<simpara>
|
|
Se <parameter>funzione</parameter> richiede più parametri di
|
|
quanti gliene vengono passati, un errore di livello <link linkend="errorfunc.constants">
|
|
E_WARNING</link> verrà generato ogni volta che <function>array_walk</function>
|
|
la chiama. Questi avvertimenti possono essere soppressi
|
|
apponendo l'operatore d'errore
|
|
<link linkend="language.operators.errorcontrol">@</link> alla
|
|
chiamata di <function>array_walk</function>, oppure usando
|
|
<function>error_reporting</function>.
|
|
</simpara>
|
|
<note>
|
|
<para>
|
|
Se <parameter>funzione</parameter> deve lavorare con i
|
|
reali valori dell'array, specificare che il primo parametro di
|
|
<parameter>funzione</parameter> deve essere passato come
|
|
<link linkend="language.references">riferimento</link>. A qesto punto
|
|
ogni modifica a questi elementi verrà effettuata sull'array
|
|
stesso.
|
|
</para>
|
|
</note>
|
|
<note>
|
|
<para>
|
|
Il passaggio della chiave e di <parameter>datiutente</parameter> a <parameter>func</parameter> è
|
|
stato aggiunto nella versione 4.0.
|
|
</para>
|
|
</note>
|
|
<para>
|
|
<function>array_walk</function> non è influenzato dal puntatore
|
|
interno dell'array <parameter>array</parameter>. <function>
|
|
array_walk</function> percorrerà l'intero array
|
|
indipendentemente dalla posizione del puntatore. Per reinizializzare il puntatore, utilizzare
|
|
<function>reset</function>. In PHP 3,
|
|
<function>array_walk</function> reinizializza il puntatore.
|
|
</para>
|
|
<para>
|
|
Gli utenti non possono modificare l'array attraverso la funzione
|
|
di callback, ad esempio aggiungere/togliere un elemento, o cancellare l'array su cui
|
|
<function>array_walk</function> è applicata. Se l'array viene
|
|
cambiato, il comportamento di questa funzione non è definito ed
|
|
è imprevedibile.
|
|
</para>
|
|
<para>
|
|
<example>
|
|
<title>esempio di <function>array_walk</function></title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$frutta = array("d"=>"limone", "a"=>"arancia", "b"=>"banana", "c"=>"mela");
|
|
|
|
function modifica(&$elemento1, $chiave, $prefisso)
|
|
{
|
|
$elemento1 = "$prefisso: $elemento1";
|
|
}
|
|
|
|
function stampa($elemento2, $chiave)
|
|
{
|
|
echo "$chiave. $elemento2<br />\n";
|
|
}
|
|
|
|
echo "Prima ...:\n";
|
|
array_walk($frutta, 'stampa');
|
|
|
|
array_walk($frutta, 'modifica', 'frutto');
|
|
echo "... e dopo:\n";
|
|
|
|
array_walk($frutta, 'stampa');
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
<para>
|
|
Il risultato del programma sarà:
|
|
</para>
|
|
<screen role="php">
|
|
<![CDATA[
|
|
Prima ...:
|
|
d. limone
|
|
a. arancia
|
|
b. banana
|
|
c. mela
|
|
... e dopo:
|
|
d. frutto: limone
|
|
a. frutto: arancia
|
|
b. frutto: banana
|
|
c. frutto: mela
|
|
]]>
|
|
</screen>
|
|
</example>
|
|
</para>
|
|
<simpara>
|
|
Vedere anche <function>array_walk_recursive</function>,
|
|
<function>create_function</function>,
|
|
<function>list</function>,
|
|
<link linkend="control-structures.foreach">foreach</link>,
|
|
<function>each</function>,
|
|
<function>call_user_func_array</function> e
|
|
<function>array_map</function>
|
|
</simpara>
|
|
</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
|
|
-->
|