如果我使用array_walk
類函數中調用同一類如何使用類方法作爲回調函數?
class user
{
public function getUserFields($userIdsArray,$fieldsArray)
{
if((isNonEmptyArray($userIdsArray)) && (isNonEmptyArray($fieldsArray)))
{
array_walk($fieldsArray, 'test_print');
}
}
private function test_print($item, $key)
{
//replace the $item if it matches something
}
}
它給了我下面的錯誤的另一個功能 -
警告:
array_walk()
[function.array步行]:無法調用test_print()
- 函數不存在...
所以,我怎麼指定$this->test_print()
WH使用array_walk()
?
任何你創建函數'isNonEmptyArray'而不是使用'!empt Y(...)'? – 2010-10-01 14:59:22
是的,只有當參數是一個至少有一個非空值的數組時,它纔會返回true – 2010-10-01 15:02:31