Re: array_walk
| From: | Dan Hardiker | Date: | Thu, 06 Jun 2002 14:33:40 +0000 |
| Subject: | Re: array_walk | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-100934@lists.php.net to get a copy of this message | ||
> Instead of passing "this" and "other" to your array, PHP
> passes "0" and "other". Is there any way I can make it
> so that it passes "this"?
[pulled from the manual directly]
Example 1. array_walk() example
$fruits = array ("d"=>"lemon", "a"=>"orange",
"b"=>"banana", "c"=>"apple");
function test_alter (&$item1, $key, $prefix) {
$item1 = "$prefix: $item1";
}
function test_print ($item2, $key) {
echo "$key. $item2<br>\n";
}
echo "Before ...:\n";
array_walk ($fruits, 'test_print');
reset ($fruits);
array_walk ($fruits, 'test_alter', 'fruit');
echo "... and after:\n";
reset ($fruits);
array_walk ($fruits, 'test_print');
The printout of the program above will be:
Before ...:
d. lemon
a. orange
b. banana
c. apple
.... and after:
d. fruit: lemon
a. fruit: orange
b. fruit: banana
c. fruit: apple
--
Dan Hardiker [dhardiker@staff.firstcreative.net]
ADAM Software & Systems Engineer
First Creative Ltd