Find the value in a multidimensional array by key
<p>UPD code: "Parse error: syntax error, unexpected '[' in E"</p>

<p>I need to find the array element value on the key value, which is obtained from a variable. In my code somewhere error. Can you help me please? Thanks!</p>

<pre><code>$city_file = 'https://pogoda.yandex.ru/static/cities.xml';   
$xml_city = simplexml_load_file($city_file); 
$cityName = 'Киев';

foreach($xml_city-&gt;country as $country){
  foreach($country-&gt;city as $city):
    $attrs = $city-&gt;attributes();
    $city = strval($city);
    $id = strval($attrs['id']);
    $cities = [];
    $cities [] = [$id=&gt;$city];
  endforeach;
}
$cityid = array_search($cityName, $cities);
echo $cities;
echo $cityid;
</code></pre>

<p>UPD 2: Thanks for all, this version is works</p>

<pre><code>    $city_file = 'https://pogoda.yandex.ru/static/cities.xml';   
$xml_city = simplexml_load_file($city_file); 
$cityName = 'Осака';
//$cities = []; - Syntax error
foreach($xml_city-&gt;country as $country){
  foreach($country-&gt;city as $city):
    $attrs = $city-&gt;attributes();
    $city = strval($city);
    $id = strval($attrs['id']);    
    $cities [$id] = $city;
  endforeach;
}

$cityid = array_search($cityName, $cities);
echo $cityid;
</code></pre>