我的多維數組是這樣的:無法從多維數組PHP刪除空值
Array
(
[0] => Array
(
[0] => 2010-12-03
[1] => 0
[2] => Array
(
[0] => Array
(
[0] =>
[1] =>
[2] => 0
[3] =>
[4] =>
)
[1] => Array
(
[0] =>
[1] =>
[2] => 0
[3] =>
[4] =>
)
[2] => Array
(
[0] =>
[1] =>
[2] => 0
[3] =>
[4] =>
)
[3] => Array
(
[0] =>
[1] =>
[2] => 0
[3] =>
[4] =>
)
[4] => Array
(
[0] =>
[1] =>
[2] => 0
[3] =>
[4] =>
)
[5] => Array
(
[0] =>
[1] =>
[2] => 0
[3] =>
[4] =>
)
)
)
[1] => Array
(
[0] => 2010-12-10
[1] => 486
[2] => Array
(
[0] => Array
(
[0] => Bob
[1] => Lucy
[2] => 54
[3] => Y
[4] => PC1Clean
)
[1] => Array
(
[0] => Jo
[1] => Mary
[2] => 432
[3] => Y
[4] => PC2Bar
)
[2] => Array
(
[0] =>
[1] =>
[2] => 0
[3] =>
[4] =>
)
[3] => Array
(
[0] =>
[1] =>
[2] => 0
[3] =>
[4] =>
)
[4] => Array
(
[0] =>
[1] =>
[2] => 0
[3] =>
[4] =>
)
[5] => Array
(
[0] =>
[1] =>
[2] => 0
[3] =>
[4] =>
)
)
)
我試過array_filter
和不同的循環迭代刪除zero
/null
值,如
function removeElementWithValue($array, $key, $value) {
foreach($array as $subKey => $subArray) {
if($subArray[$key] == $value) {
unset($array[$subKey]);
}
}
}
但似乎沒有任何工作。任何幫助將非常感激!
我認爲這是變量'$ array'範圍的問題。 – fehnomenal
您需要將參考傳遞給您的函數,否則您不會從原始數組中取消設置 –
http://rogerpadilla.wordpress.com/2009/08/21/remove-empty-items-from-array/ – softsdev