从数组返回单个变量
我正在使用以下脚本:
http://www.micahcarrick .com/php-zip-code-range-and-distance-calculation.html
要获取邮政编码的详细信息,我使用以下命令:
$selected = $z->get_zip_details($zip);
$result = implode(",", $selected);
echo $result;
这将返回“$zip”的所有详细信息:
32.9116,-96.7323 ,Dallas,Dallas,TX,Texas,214,Central
任何1都可以帮助我使脚本仅返回城市变量吗?该脚本的常见问题解答如下:
get_zip_details($zip)
Returns the details about the zip code: $zip. Details are in the form of a keyed array. The keys are: latitude, longitude, city, county, state_prefix, state_name, area_code, and time_zone. All are pretty self-explanitory. Returns false on error.
不幸的是,我无法弄清楚如何获取单个值(城市)。将不胜感激任何帮助!
谢谢!
i am using following script:
http://www.micahcarrick.com/php-zip-code-range-and-distance-calculation.html
To get the details for a ZIP code, I am using this:
$selected = $z->get_zip_details($zip);
$result = implode(",", $selected);
echo $result;
This returns all details of "$zip" :
32.9116,-96.7323,Dallas,Dallas,TX,Texas,214,Central
Could any1 help me to make the script return ONLY the city variable? The FAQ of the script, says the following:
get_zip_details($zip)
Returns the details about the zip code: $zip. Details are in the form of a keyed array. The keys are: latitude, longitude, city, county, state_prefix, state_name, area_code, and time_zone. All are pretty self-explanitory. Returns false on error.
Unfortunately I cant figure out how to get a single value (city). Would appreciate any help!
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这些函数返回一个数组,因此我们必须将其存储在变量中。
接下来,我们可以选择指向城市的键。钥匙也称为城市。
The functions is returning an array, so we have to store it in a variable.
Next, we can select the key which points to the city. The key is also called city.
更改此行
至
Change this line
To
为了将来参考,
implode()
explode()
等都是数组函数。因此,如果您在某些东西上使用它们,那么您可以print_r()
它来查看其结构。如果您执行了
print_r($selected);
或var_dump($selected);
,您将得到类似这样的输出:数组以了解如何访问各个值。
For future reference,
implode()
explode()
etc. are array functions. So, if you're using them on something then you canprint_r()
it to see its structure.If you had done
print_r($selected);
orvar_dump($selected);
, you would have gotten something like this as output:So you can see the keys of the array to know how to access the individual values.