How to delete object from array inside foreach loop?

前端 未结 6 1583
情书的邮戳
情书的邮戳 2020-11-28 21:00

I iterate through an array of objects and want to delete one of the objects based on it\'s \'id\' property, but my code doesn\'t work.

foreach($array as $ele         


        
6条回答
  •  北海茫月
    2020-11-28 21:20

    I'm not much of a php programmer, but I can say that in C# you cannot modify an array while iterating through it. You may want to try using your foreach loop to identify the index of the element, or elements to remove, then delete the elements after the loop.

提交回复
热议问题