嗨,有一个数组保存在变量$someArray
中。这是$someArray
的内容:
Array (
[0] => Array (
[CityDesc] => Burgbretzingen
[CityId] => 63910
)
[1] => Array (
[CityDesc] => Bühlerzimmern
[CityId] => 1288010
)
[2] => Array (
[CityDesc] => Einkorn
[CityId] => 320610
)
[3] => Array
(
[CityDesc] => Scherbenmühle
[CityId] => 711910
)
[4] => Array (
[CityDesc] => Schwäbisch Hall
[CityId] => 1694510
)
[5] => Array (
[CityDesc] => Traubenmühle
[CityId] => 493610
)
)
如果我搜索63910
,我将读出此值"Burgbretzingen"
([CityId])。
答案 0 :(得分:2)
您可以使用array_column
$res = array_column($a, 'CityId', 'CityDesc');
echo empty($res['Burgbretzingen']) ? '' : $res['Burgbretzingen'];
工作示例:-https://3v4l.org/s1TNk