Get array values by keys

I think you are searching for array_intersect_key. Example:

array_intersect_key(array('a' => 1, 'b' => 3, 'c' => 5), 
                    array_flip(array('a', 'c')));

Would return:

array('a' => 1, 'c' => 5);

You may use array('a' => '', 'c' => '') instead of array_flip(...) if you want to have a little simpler code.

Note the array keys are preserved. You should use array_values afterwards if you need a sequential array.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)