如果你不想使用for循环。考虑到你只有一种活动语言。如果您有多个,将取第一个。
$array = array(
'en' => array('active' => '0', 'default_locale' => 'en_US',),
'es' => array('active' => '1','default_locale' => 'es_ES',),
'de' => array('active' => '0','default_locale' => 'de_DE', ),
'fr' => array('active' => '0','default_locale' => 'fr_FR', )
);
// get all the keys of your array
$array_keys = array_keys($array);
// serach for active language
$search = array_search('1', array_column($array, 'active'));
// named key
$named_key = $array_keys[$search]; // returns 'es' in this case.
// print your active array
print_r($array[$named_key]);
输出:
Array
(
[active] => 1
[default_locale] => es_ES
)