i'm parsing a json file (api rest) but i can't solve a problem. This is the json file.
Array
(
[110197275197292] => Array
(
[mid] => 110197275197292
[home] => FC Den Bosch
[away] => SC Telstar
[country_leagues] => Netherlands - Eerste Divisie
[leagues] => Eerste Divisie
[country] => Netherlands
[score] =>
[home_score] => 0
[away_score] => 0
[periodID] =>
[periodTXT] =>
[periodTime] => 1632923759
[startTime] => 1633111200
[lastUpdateTime] => 1632923357
[minutes] => 0
[status] => 1
[importancy] => 281
[odds] => Array
(
[home] => 2.45
[draw] => 3.70
[away] => 2.40
[1st-1] => 2.90
[1st-0] => 2.35
[1st-2] => 2.87
[2nd-1] => 2.70
[2nd-0] => 2.70
[2nd-2] => 2.65
with this code below i print the value of the array, and work.
foreach ($response as $key1 => $value1){
echo $response[$key1]['home'] .'<br>';
}
Now i would insert the value of the array in a variable, something like that
foreach ($response as $key1 => $value1){
$prova = $response[$key1]['home'];
}
<?php echo $prova; ?>
This way I could recall it in an html table. This code print me only one value of the array and does not loop (foreach). The value that prints in this case is Nashville SC which is a value found in the json file. Where is my mistake? there is a way to encapsulate array values in a variable and then recall it later in the html code?
My Answer:
{
"id": 110197275197292,
"name": "John Doe",
"age": 30,
"email": "johndoe@example.com"
}
Rate this post
3 of 5 based on 8650 votesComments