php - Searching nested arrays and returning the key from a matching value -
[ [mile] => [ [acronym] => mi ], [kilometer] => [ [acronym] => km ] ] $acronym = 'km';
how may return key name matching acronym
value? in example want return kilometer
.
this should work you:
here create array array_combine()
use array_column()
keyname acronym
keys , array_keys()
$arr
values.
<?php $acronym = "km"; $arr = array_combine(array_column($arr, "acronym"), array_keys($arr)); echo $arr[$acronym]; ?>
output:
kilometer
Comments
Post a Comment