mirror of
https://github.com/php/doc-fr.git
synced 2026-03-24 23:22:18 +01:00
git-svn-id: https://svn.php.net/repository/phpdoc/fr/trunk@114768 c90b9560-bf6c-de11-be94-00142212c4b1
126 lines
4.0 KiB
XML
126 lines
4.0 KiB
XML
<?xml version="1.0" encoding="iso-8859-1"?>
|
|
<!-- splitted from ./fr/functions/array.xml, last change in rev 1.30 -->
|
|
<!-- last change to 'array-walk' in en/ tree in rev 1.2 -->
|
|
<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>int</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>func</parameter>
|
|
avec chaque élément du tableau <parameter>arr</parameter>. Les
|
|
éléments sont passés en tant que premier argument de la
|
|
fonction <parameter>func</parameter>. <parameter>func</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.
|
|
</simpara>
|
|
<simpara>
|
|
Si <parameter>func</parameter> a besoin de plus d'un argument, une alerte
|
|
sera générée pour chaque appel de <parameter>func</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>func</parameter> doit travailler avec les véritables
|
|
valeurs du tableau, spécifiez que le premier paramètre de
|
|
<parameter>func</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>func</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 réinitialise 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>
|
|
<para>
|
|
L'affichage de ce script sera :
|
|
<screen role="php">
|
|
<![CDATA[
|
|
d. citron<br>
|
|
a. orange<br>
|
|
b. banane<br>
|
|
c. pomme<br>
|
|
d. fruit: citron<br>
|
|
a. fruit: orange<br>
|
|
b. fruit: banane<br>
|
|
c. fruit: pomme<br>
|
|
]]>
|
|
</screen>
|
|
</para>
|
|
</example>
|
|
</para>
|
|
<simpara>
|
|
Voir aussi
|
|
<function>each</function> et
|
|
<function>list</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
|
|
-->
|