如何回显出这个数组的值?

时间:2022-12-29 15:43:43

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?

这个回声是整个字符串不作为数组。如果我这样做?

  echo $value[0};

Then i only get 2 characters of it??

那我只得到2个字符?

EDIT:

编辑:

The print_r :

print_r:

Array ( [0] => 20120430 [1] => My Event 1 )

数组([0] => 20120430 [1] =>我的事件1)

Thanks

谢谢

Chris

克里斯

4 个解决方案

#1


20  

foreach ($array as $key => $val) {
   echo $val;
}

#2


2  

Here is a simple routine for an array of primitive elements:

这是一个原始元素数组的简单例程:

for ($i = 0; $i < count($mySimpleArray); $i++)
{
   echo $mySimpleArray[$i] . "\n";
}

#3


0  

you need the set key and value in foreach loop for that:

你需要foreach循环中的set键和值:

foreach($item AS $key -> $value) {
echo $value;
}

this should do the trick :)

这应该做的伎俩:)

#4


0  

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,如果这是您要做的事情。否则我不完全确定你要打印什么。

#1


20  

foreach ($array as $key => $val) {
   echo $val;
}

#2


2  

Here is a simple routine for an array of primitive elements:

这是一个原始元素数组的简单例程:

for ($i = 0; $i < count($mySimpleArray); $i++)
{
   echo $mySimpleArray[$i] . "\n";
}

#3


0  

you need the set key and value in foreach loop for that:

你需要foreach循环中的set键和值:

foreach($item AS $key -> $value) {
echo $value;
}

this should do the trick :)

这应该做的伎俩:)

#4


0  

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,如果这是您要做的事情。否则我不完全确定你要打印什么。