array_walk类调用

$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');

array_walk($fruits, 'test_alter', 'fruit');
echo "... and after:\n";

array_walk($fruits, 'test_print');

如果是在类中,调用自身的方法应该怎么调用呢?

应该是将参数做为数组传入:array_walk($datas, array($this, "_function"));将$this指针一起带入!

你可能感兴趣的:(array_walk类调用)