我有數組:如何在PHP中刪除數組元素?
陣列:
Array
(
[0] => Array
(
[name] => point
[visibility] =>
)
[1] => Array
(
[name] => php_first_table
[visibility] => 1
)
[2] => Array
(
[name] => ohz
[visibility] => 1
)
)
現在我想找到與name=ohz
刪除元素:
for($i=0;$i<count($arrays);$i++){
if(array_search("ohz",$arrays[$i])){
unset($arrays[$i]);
}
}
print_r($arrays);
輸出:
Array
(
[0] => Array
(
[name] => point
[visibility] =>
)
[2] => Array
(
[name] => ohz
[visibility] => 1
)
)
爲什麼php_first_table
不ohz
被刪除?
的代碼應該可以正常工作。你能否提供一個具有這種行爲的完整程序? – Jon