I have an array and a number, assigned to the variable $cat
.
$categories_array = array(
"Belts" => array(131),
"Headwear" => array(171,172,185,186),
"ScarvesAndGloves" => array(166,173,184)
);
If $cat
is 171, I want $category
to be Headwear
.
I've looked at array_search
but it doesn't seem to work for multidimensional arrays. All solutions I've found around the site seem to rely on a key for each of the entries in the sub-array. I just want to assign the name of the key to the variable if it appears in the array. There will be no duplicates.
Can it be achieved in this format or should I be re-structuring this array? Is there a better way of achieving this result?