帮助处理大数组
我是 php 新手,我正在尝试使用数组从字符串中过滤一些单词,这是数组:
$array_lugares = array
(
array("barra"=>array
(
/*SENTIDO BARRA*/
"Sao conrado"=>array("-22.999743","-43.270694"),
"Elevado do Joa"=>array("-22.999429","-43.27317")
),
"zona sul"=>array
(
/*SENTIDO ZONA SUL:*/
"passarela da barra"=>array("-23.008346","-43.303708"),
"barra grill"=>array("-23,010576", "-43,302028"),
"lagoa barra"=>array("-22,997348", "-43,263200")
),
"recreio"=>array
(
/*SENTIDO RECREIO:*/
"passarela da barra"=>array("-23.008283","-43.303634"),
"rio mar"=>array("22.999958","-43.402648"),
"ribalta"=>array("-22,999753", "-43,409211")
)));
当我这样做时:
foreach($array_lugares[0]['zona sul'] as $lugar){
echo $lugar;
echo "</br>";
}
输出是:
Array
Array
Array
我怎样才能使它显示:
barra
zona sul
recreio
在输出中,是吗可能的 ?
i'm new to php and i'm trying to filter some words from a string, using an array, here's the array:
$array_lugares = array
(
array("barra"=>array
(
/*SENTIDO BARRA*/
"Sao conrado"=>array("-22.999743","-43.270694"),
"Elevado do Joa"=>array("-22.999429","-43.27317")
),
"zona sul"=>array
(
/*SENTIDO ZONA SUL:*/
"passarela da barra"=>array("-23.008346","-43.303708"),
"barra grill"=>array("-23,010576", "-43,302028"),
"lagoa barra"=>array("-22,997348", "-43,263200")
),
"recreio"=>array
(
/*SENTIDO RECREIO:*/
"passarela da barra"=>array("-23.008283","-43.303634"),
"rio mar"=>array("22.999958","-43.402648"),
"ribalta"=>array("-22,999753", "-43,409211")
)));
when I do:
foreach($array_lugares[0]['zona sul'] as $lugar){
echo $lugar;
echo "</br>";
}
the output is:
Array
Array
Array
how can I make it so it shows:
barra
zona sul
recreio
in the output, is it possible ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
那是因为你有一个多维数组,你也可以循环
$lugar;
,它会给你正确的输出更新:
但我认为你应该重新访问你拥有的代码,看看这是否是确实是您想要的数据处理方式
That is because you have a multidimensional array, you can loop through
$lugar;
also, and it will give you the correct outputUpdate:
but i think you should revisit the code you have and see if this is really the way you want to work with your data
这是因为
$array_logares[0]['zona sul']
为您提供了对象,并且每个元素是一个(点)数组。如果您想要名称(而不是点数组),您可以这样做:
如果您想要名称和点,您可以这样做:
that's because
$array_logares[0]['zona sul']
is giving you the objectand each element is an array (of points). If you want the names (instead of the array of points) you would do this:
if you want the name and the point, you would do this: