Tôi lặp qua một mảng các đối tượng và muốn xóa một trong các đối tượng dựa trên thuộc tính 'id' của nó, nhưng mã của tôi không hoạt động.Làm thế nào để xóa đối tượng khỏi mảng bên trong vòng lặp foreach?
foreach($array as $element) {
foreach($element as $key => $value) {
if($key == 'id' && $value == 'searched_value'){
//delete this particular object from the $array
unset($element);//this doesn't work
unset($array,$element);//neither does this
}
}
}
Mọi đề xuất. Cảm ơn.
thể trùng lặp của [Làm thế nào để bạn loại bỏ một phần tử mảng trong một foreach loop?] (http://stackoverflow.com/questions/1949259/how-do-you-remove-an-array-element-in-a-foreach-loop) – 7hi4g0