mirror of
https://github.com/macintoshplus/doc-fr.git
synced 2026-03-25 17:32:07 +01:00
git-svn-id: https://svn.php.net/repository/phpdoc/fr/trunk@163075 c90b9560-bf6c-de11-be94-00142212c4b1
130 lines
3.9 KiB
XML
130 lines
3.9 KiB
XML
<?xml version="1.0" encoding="iso-8859-1"?>
|
|
<!-- $Revision: 1.15 $ -->
|
|
<!-- EN-Revision: 1.18 Maintainer: dams Status: ready -->
|
|
<refentry id="function.array-walk">
|
|
<refnamediv>
|
|
<refname>array_walk</refname>
|
|
<refpurpose>
|
|
Exécute une fonction sur chacun des membres d'un tableau
|
|
</refpurpose>
|
|
</refnamediv>
|
|
<refsect1>
|
|
<title>Description</title>
|
|
<methodsynopsis>
|
|
<type>bool</type><methodname>array_walk</methodname>
|
|
<methodparam><type>array</type><parameter>array</parameter></methodparam>
|
|
<methodparam><type>callback</type><parameter>function</parameter></methodparam>
|
|
<methodparam choice="opt"><type>mixed</type><parameter>userdata</parameter></methodparam>
|
|
</methodsynopsis>
|
|
<simpara>
|
|
<function>array_walk</function> exécute la fonction <parameter>function</parameter>
|
|
avec chaque élément du tableau <parameter>array</parameter>. Les
|
|
éléments sont passés en tant que premier argument de la
|
|
fonction <parameter>function</parameter>. <parameter>function</parameter> doit être
|
|
une fonction définie par l'utilisateur, et non pas une fonction native
|
|
&php;. Vous ne pouvez pas utiliser <function>array_walk</function> directement
|
|
avec <function>str2lower</function>, il faut absolument passer par une fonction
|
|
utilisateur. &return.success;
|
|
</simpara>
|
|
<simpara>
|
|
Si <parameter>function</parameter> a besoin de plus d'un argument, une alerte
|
|
sera générée pour chaque appel de <parameter>function</parameter>.
|
|
Ces alertes sont supprimées en ajoutant le suffixe '@' avant l'appel de
|
|
<function>array_walk</function> ou simplement en utilisant
|
|
<function>error_reporting</function>.
|
|
</simpara>
|
|
<note>
|
|
<para>
|
|
Si <parameter>function</parameter> doit travailler avec les véritables
|
|
valeurs du tableau, spécifiez que le premier paramètre de
|
|
<parameter>function</parameter> doit être passé par
|
|
référence. Alors, les éléments seront directement
|
|
modifiés dans le tableau.
|
|
</para>
|
|
</note>
|
|
<note>
|
|
<para>
|
|
Passer les clés et <parameter>userdata</parameter> à
|
|
<parameter>function</parameter> a été ajouté en &php; 4.0.
|
|
</para>
|
|
<para>
|
|
En &php; 4, <function>reset</function> doit être appelé si
|
|
nécessaire, car <function>array_walk</function> ne reinitialise pas
|
|
automatiquement le tableau.
|
|
</para>
|
|
</note>
|
|
<para>
|
|
<example>
|
|
<title>Exemple avec <function>array_walk</function></title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?&php;
|
|
$fruits = array ("d"=>"citron", "a"=>"orange", "b"=>"banane", "c"=>"pomme");
|
|
|
|
function test_alter (&$item1, $key, $prefix) {
|
|
$item1 = "$prefix: $item1";
|
|
}
|
|
|
|
function test_print ($item2, $key) {
|
|
echo "$key. $item2<br />\n";
|
|
}
|
|
|
|
array_walk ($fruits, 'test_print');
|
|
reset ($fruits);
|
|
|
|
array_walk ($fruits, 'test_alter', 'fruit');
|
|
reset ($fruits);
|
|
|
|
array_walk ($fruits, 'test_print');
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
&example.outputs;
|
|
<screen role="php">
|
|
<![CDATA[
|
|
d. citron
|
|
a. orange
|
|
b. banane
|
|
c. pomme
|
|
d. fruit: citron
|
|
a. fruit: orange
|
|
b. fruit: banane
|
|
c. fruit: pomme
|
|
]]>
|
|
</screen>
|
|
</example>
|
|
</para>
|
|
<simpara>
|
|
Voir aussi
|
|
<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> et
|
|
<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:"../../../../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
|
|
-->
|