php 如何回显这个数组的值?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10584784/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to echo out the values of this array?
提问by Chris Till
How to echo out the values individually of this array?
如何单独回显此数组的值?
Array ( [0] => 20120514 [1] => My Event 3 )
so
所以
echo $value[0]; etc
I have this so far:
到目前为止我有这个:
foreach (json_decode($json_data_string, true) as $item) {
$eventDate = trim($item['date']);
// positive limit
$myarray = (explode(',', $eventDate, 2));
foreach ($myarray as $value) {
echo $value;
}
This echo's out the whole string no as an array. and if i do this?
这个回声将整个字符串 no 作为一个数组。如果我这样做?
echo $value[0};
Then i only get 2 characters of it??
然后我只得到了 2 个字符??
EDIT:
编辑:
The print_r :
打印_r :
Array ( [0] => 20120430 [1] => My Event 1 )
数组 ( [0] => 20120430 [1] => 我的事件 1 )
Thanks
谢谢
Chris
克里斯
回答by hohner
foreach ($array as $key => $val) {
echo $val;
}
回答by wolfstevent
Here is a simple routine for an array of primitive elements:
这是原始元素数组的简单例程:
for ($i = 0; $i < count($mySimpleArray); $i++)
{
echo $mySimpleArray[$i] . "\n";
}
回答by Avihay Menahem
you need the set key and value in foreach loop for that:
为此,您需要在 foreach 循环中设置键和值:
foreach($item AS $key -> $value) {
echo $value;
}
this should do the trick :)
这应该可以解决问题:)
回答by DaOgre
The problem here is in your explode statement
这里的问题在于你的爆炸声明
//$item['date'] presumably = 20120514. Do a print of this
$eventDate = trim($item['date']);
//This explodes on , but there is no , in $eventDate
//You also have a limit of 2 set in the below explode statement
$myarray = (explode(',', $eventDate, 2));
//$myarray is currently = to '20'
foreach ($myarray as $value) {
//Now you are iterating through a string
echo $value;
}
Try changing your initial $item['date'] to be 2012,04,30 if that's what you're trying to do. Otherwise I'm not entirely sure what you're trying to print.
如果这就是您想要做的,请尝试将您的初始 $item['date'] 更改为 2012,04,30。否则我不完全确定你要打印什么。
回答by Tayyab Hayat
var_dump($value)
it solved my problem, hope yours too.
它解决了我的问题,希望你也是。

