Answer the question
In order to leave comments, you need to log in
How to pass data from PHP array to variables?
Hello! Never encountered an array in PHP...
Here it is:
var_export($SxGeo->getCityFull($ip)); // Вся информация о городе
array ( 'city' => array ( 'id' => 520555, 'lat' => 56.32867, 'lon' => 44.00205, 'name_ru' => 'Нижний Новгород', 'name_en' => 'Nizhniy Novgorod', 'okato' => '22401', ), 'region' => array ( 'id' => 559838, 'lat' => 56, 'lon' => 45, 'name_ru' => 'Нижегородская область', 'name_en' => 'Nizhegorodskaya Oblast\'', 'iso' => 'RU-NIZ', 'timezone' => 'Europe/Moscow', 'okato' => '22', ), 'country' => array ( 'id' => 185, 'iso' => 'RU', 'continent' => 'EU', 'lat' => 60, 'lon' => 100, 'name_ru' => 'Россия', 'name_en' => 'Russia', 'timezone' => 'Europe/Moscow', ), )
Answer the question
In order to leave comments, you need to log in
The purpose of translating an array into variables is not entirely clear, because you can use it like this:
$arr = $SxGeo->getCityFull($ip);
echo $arr['city']['name_ru'];
Use the extract()
function
Example from php.net/manual/ru/function.extract.php
<?php
/* Предположим, что $var_array - это массив, полученный в результате
wddx_deserialize */
$size = "large";
$var_array = array("color" => "blue",
"size" => "medium",
"shape" => "sphere");
extract($var_array, EXTR_PREFIX_SAME, "wddx");
echo "$color, $size, $shape, $wddx_size\n";
?>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question