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

Popular posts from this blog

apache - PHP Soap issue while content length is larger -

asynchronous - Python asyncio task got bad yield -

javascript - Complete OpenIDConnect auth when requesting via Ajax -