Deleting an element from an array in PHP

后端 未结 30 3266
时光说笑
时光说笑 2020-11-21 05:55

Is there an easy way to delete an element from an array using PHP, such that foreach ($array) no longer includes that element?

I thought that setting it

30条回答
  •  我在风中等你
    2020-11-21 06:50

    Suppose you have the following array:

    Array
    (
        [user_id] => 193
        [storage] => 5
    )
    

    To delete storage, do:

    unset($attributes['storage']);
    $attributes = array_filter($attributes);
    

    And you get:

    Array
    (
        [user_id] => 193
    )
    

提交回复
热议问题