cvs: /phpdoc/functions array.sgml

From: Date: Sat, 14 Aug 1999 16:47:11 +0000
Subject: cvs: /phpdoc/functions array.sgml
Groups: php.dev 
Request: Send a blank email to php-dev+get-9854@lists.php.net to get a copy of this message
andrey Sat Aug 14 12:47:11 1999 EDT Modified files: /phpdoc/functions array.sgml Log: Modified array_walk docs. Index: phpdoc/functions/array.sgml diff -u phpdoc/functions/array.sgml:1.17 phpdoc/functions/array.sgml:1.18 --- phpdoc/functions/array.sgml:1.17 Wed Jul 21 09:55:46 1999 +++ phpdoc/functions/array.sgml Sat Aug 14 12:47:11 1999 @@ -498,13 +498,20 @@ <funcdef>int <function>array_walk</function></funcdef> <paramdef>array <parameter>arr</parameter></paramdef> <paramdef>string <parameter>func</parameter></paramdef> + <paramdef>mixed <parameter>userdata</parameter></paramdef> </funcsynopsis> <simpara> Applies the function named by <parameter>func</parameter> to each - element of <parameter>arr</parameter>. The elements are passed as - the first argument of <parameter>func</parameter>; if - <parameter>func</parameter> requires more than one argument, a + element of + <parameter>arr</parameter>. <parameter>func</parameter> will be + passed array value as the first parameter and array key as the + second parameter. If <parameter>userdata</parameter> is + supplied, it will be passed as the third parameter to the user + function. + + If <parameter>func</parameter> requires more than two or three + arguments, depending on <parameter>userdata</parameter>, a warning will be generated each time <function>array_walk</function> calls <parameter>func</parameter>. These warnings may be suppressed by @@ -513,9 +520,11 @@ <note> <para> - <parameter>func</parameter> will actually be working with the - elements of <parameter>arr</parameter>, so any changes made to - those elements will be made in the array itself. + If <parameter>func</parameter> needs to be working with the + actual values of the array, specify that the first parameter of + <parameter>func</parameter> should be passed by reference. Then + any changes made to those elements will be made in the array + itself. </para> </note> @@ -525,16 +534,16 @@ <programlisting> $fruits = array("d"=>"lemon","a"=>"orange","b"=>"banana","c"=>"apple"); -function test_alter( $item1 ) { - $item1 = 'bogus'; +function test_alter( &$item1, $key, $prefix ) { + $item1 = "$prefix: $item1"; } -function test_print( $item2 ) { - echo "$item2&lt;br&gt;\n"; +function test_print( $item2, $key ) { + echo "$key. $item2&lt;br&gt;\n"; } array_walk( $fruits, 'test_print' ); -array_walk( $fruits, 'test_alter' ); +array_walk( $fruits, 'test_alter', 'fruit' ); array_walk( $fruits, 'test_print' ); </programlisting> </example>

« previous php.dev (#9854) next »