Skip to content
Advertisement

Return all array elements except for a given key

Simple one, I was just wondering if there is a clean and eloquent way of returning all values from an associative array that do not match a given key(s)?

JavaScript

This is what I’m (going to be) using, however, are there cleaner implementations, something I missed in the manual perhaps?

Advertisement

Answer

You could just unset the value:

JavaScript

Edit: Made it clearer. You can copy an array by assigning it to another variable.

or in a function:

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement