0

Lets say I have the following array:

$v = Array
(
    [0] => Array
        (
            [a] => 1
            [b] => 2
        )
    [1] => Array
        (
            [a] => 11
            [b] => 22
        )
)

Is there a native function taking the array and a key as input, and returning an array of all the values for the given key? With the above example it would give:

php> find_values_by_key($v, 'b');
Array( [0] => 2, [1] => 22 )

(I know I could write my own function, I'm just wondering if a native one exists).

gregseth
  • 12,952
  • 15
  • 63
  • 96
  • 1
    Think you're looking for `array_column`. – Don't Panic Dec 08 '19 at 19:30
  • The duplicate is based on the array having the same format as you have in your example, there may be other times when the key is potentially at different depths which is a different thing. – Nigel Ren Dec 08 '19 at 19:32

0 Answers0