How to delete object from array inside foreach loop?

前端 未结 6 1596
情书的邮戳
情书的邮戳 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:31

    It looks like your syntax for unset is invalid, and the lack of reindexing might cause trouble in the future. See: the section on PHP arrays.

    The correct syntax is shown above. Also keep in mind array-values for reindexing, so you don't ever index something you previously deleted.

提交回复
热议问题