how to remove an element from an array with the data-new key
array("data-new" => 1,"data-name" => "1","data-balanse" => 1) 1,"data-name" => "1"...">
how to remove an element from an array with the data-new key
array("data-new" => 1,"data-name" => "1","data-balanse" => 1) to remove the first (zero) element of an array, use array_unshift() . This method will return the first element and change the array passed by reference. (for removal from the end use array_pop() )
$first = array_unshift($data) another option would be to use array_slice() , here the array will be returned, not changed.
$new = array_slice($data, 1); To remove a given key, use the unset() construct, and unset can take several arguments at once, and generally apply not only to array keys.
unset($data['key']) unset($data['key1'], $data['key2']) if the keys for deletion are in a separate array, you can use the functions array_diff_key()
$remove = ['key1', 'key2']; $new = array_diff_key($data, array_flip($remove)); $array = ["data-new" => 1,"data-name" => "1","data-balanse" => 1]; unset($array['data-new']); Source: https://ru.stackoverflow.com/questions/836273/
All Articles