note 17304 deleted from function.array-walk by jimw
| From: | jimw@php.net | Date: | Fri, 07 Dec 2001 01:17:37 +0000 |
| Subject: | note 17304 deleted from function.array-walk by jimw | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-21760@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");
*/