note 10591 deleted from function.array-walk by jimw
| From: | jimw@php.net | Date: | Fri, 07 Dec 2001 01:42:08 +0000 |
| Subject: | note 10591 deleted from function.array-walk by jimw | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-21763@lists.php.net to get a copy of this message | ||
Here's a similar function:
Function Array_Walk2($Array, $Function)
{
// This function will apply a function to all an array's values.
// The values will be quoted in the function call if $Use_Quotes is true.
// Only deal with array's and real functions.
If (!Is_Array($Array) OR !Function_Exists($Function)) Return $Array;
// Force pointer to be at the first element of the array.
Reset($Array);
// Iterate through all values.
While(List($Key, $Value) = Each($Array))
{
// If the element is an array, do that too.
If (Is_Array($Array[$Key]))
{
// It's an array, let's get recursive.
$Array[$Key] = Array_Walk2($Array[$Key], $Function);
}
Else // !Is_Array($Array[$Key])
{
// It's a value, let's do our magic.
Eval("\$Array[$Key] = $Function(\"$Array[$Key]\");");
}
}
Return $Array;
}