note 17304 added to function.array-walk
| From: | nospam at hahanospam4me dot com | Date: | Tue, 04 Dec 2001 00:07:10 +0000 |
| Subject: | note 17304 added to function.array-walk | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-21580@lists.php.net to get a copy of this message | ||
TIP: Any function to be used with array_walk() should expect arguments representing a value, a key
and optionally a further argument.
EXAMPLE:
// the function
function printit( $stuff, $key, $a_arg = 0)
{
print $stuff." = not an argument $key = top level key<br>\n";
if( $a_arg != 0 && is_array($a_arg) )
{
foreach( $a_arg as $key2=>$val )
{
print $val." = argument & $key2 = 2nd level key & $key = top level
key<br>\n";
}
}
print "done<br>\n";
}
// the array & optional arguments
$the_array = array("Item 1","Item2","Item3");
$args = array("argument1","argument2,"argument3");
// the call to array_walk
array_walk($the_array,"printit",$args);
/*
or since I have made the arguments optional...it could just simply be:
array_walk($the_array,"printit");
*/
--
http://www.php.net/manual/en/function.array-walk.php
http://master.php.net/manage/user-notes.php?action=edit+17304
http://master.php.net/manage/user-notes.php?action=delete+17304
http://master.php.net/manage/user-notes.php?action=reject+17304