Removing a value from a PHP Array

前端 未结 3 817
逝去的感伤
逝去的感伤 2021-01-14 19:39

Using PHP I\'m trying to remove an element from an array based on the value of the element.

For example with the following array:

Array
(
    [671] =         


        
3条回答
  •  囚心锁ツ
    2021-01-14 20:38

    Couple of ideas:

    You could try array_filter, passing in a callback function that returns false if the value is the one you want to unset. Using your example above:

    $new_inner_array = array_filter($inner_array, $callback_that_returns_false_if_value_100)

    If you want to do something more elaborate, you could explore the ArrayIterator class of the SPL, specifically the offsetUnset() method.

提交回复
热议问题