我有以下POST數組:PHP:過濾多維POST陣列
[projects] => Array (
[0] => Array
(
[description] => description 1
[path] => url 1
)
[1] => Array
(
[description] => description2
[path] => url 2
)
[2] => Array
(
[description] => description 3
[path] => url 3
)
)
我希望它與filter_var_array($_POST, $this -> fields);
其中字段= array('projects' => array('filter' => FILTER_CALLBACK,'flags' => FILTER_FORCE_ARRAY, 'options' => array($this, 'cleanProjects'));
但是,值傳遞給cleanProjects功能被過濾不是包含描述和路徑的數組,但它將所有值逐個傳遞(所以方法被稱爲六次,描述1的描述爲1,描述1爲1,描述2的描述爲1)。
我有過濾器嗎?函數將整個對象傳遞給回調函數? 因此,它會爲項目中的每個對象/數組調用cleanProjects(在本例中爲3次)。
如果你只想調用一次,爲什麼還要用'filter_var'呢?爲什麼不做'$ this-> cleanProjects($ _ POST ['projects']);'? – DaveRandom
我希望每個項目都能調用一次。整個帖子更大,項目只是其中的一個領域。 – rsids