空值有了這種簡單陣列的整個子陣:刪除包含從多維數組在PHP
array(3) {
[0]=
array(5) {
[0]=
string(61) "ramdom test"
[1]=
string(7) "19"
[2]=
string(7) "-99"
[3]=
string(6) "ramdom test"
[4]=
string(31) "ramdom test"
}
[1]=
array(5) {
[0]=
string(61) "ramdom test 2"
[1]=
string(7) "87"
[2]=
string(7) "-42"
[3]=
string(6) "NULL" // <--------------------------- THIS HAS A NULL VALUE
[4]=
string(31) "ramdom test 2"
}
[2]=
array(5) {
[0]=
string(61) "ramdom test 3"
[1]=
string(7) "54"
[2]=
string(7) "-67"
[3]=
string(6) "ramdom test 3"
[4]=
string(31) "ramdom test 3"
}
}
我想刪除包含NULL
值的整個子陣,在這種情況下,關鍵陣列的[3]
有空,所以我想如何刪除整個[1]
陣列,以便我可以得到所需的輸出?
array(2) {
[0]=
array(5) {
[0]=
string(61) "ramdom test"
[1]=
string(7) "19"
[2]=
string(7) "-99"
[3]=
string(6) "ramdom test"
[4]=
string(31) "ramdom test"
}
[1]=
array(5) {
[0]=
string(61) "ramdom test 3"
[1]=
string(7) "54"
[2]=
string(7) "-67"
[3]=
string(6) "ramdom test 3"
[4]=
string(31) "ramdom test 3"
}
}
我使用:
$myArray = array_map('array_filter', $myArray);
但這刪除我的只有空項目,而不是整個子陣列。
你需要實現檢測,如果給定的陣列相匹配的條件下的自己,簡單的回調函數。 – arkascha