How to output the values ​​of this array?

How to echo values ​​individually from this array?

Array ( [0] => 20120514 [1] => My Event 3 ) 

So

  echo $value[0]; etc 

I still have this:

 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 prints the entire string no as an array. and if i do this?

  echo $value[0}; 

Then I get only 2 characters?

EDIT:

Print_r:

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

thanks

Chris

+6
source share
4 answers
 foreach ($array as $key => $val) { echo $val; } 
+19
source

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

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

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

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

this should do the trick :)

0
source

The problem here is in your blast 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 the starting $ item ['date'] to 2012.04.30 if that is what you are trying to do. Otherwise, I'm not quite sure what you are trying to print.

0
source

Source: https://habr.com/ru/post/915679/


All Articles