0

my link json enter link description here

get it stage_name , start_time , name

$someObject = file_get_contents("http://varzesht.com/my/live.php");
foreach($someObject as $value) {
    echo $value->stage_name;
    foreach($someObject->matches as $value) {
        echo $value->start_time . "<br>". $value->name;
    }
}
RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
varzesht
  • 25
  • 1
  • 7
  • 4
    Not sure what the question is here? Are you having a problem with your code? – Nigel Ren Sep 17 '18 at 10:09
  • 2
    Look up `json_decode()` [in the manual](http://php.net/manual/en/function.json-decode.php) – RiggsFolly Sep 17 '18 at 10:10
  • Welcome, to improve your experience on SO please read how to ask an [On Topic question](https://stackoverflow.com/help/on-topic), and the [Question Check list](https://meta.stackoverflow.com/questions/260648/stack-overflow-question-checklist) and [the perfect question](http://codeblog.jonskeet.uk/2010/08/29/writing-the-perfect-question/) and how to create a [Minimal, Complete and Verifiable Example](http://stackoverflow.com/help/mcve) and [take the tour](http://stackoverflow.com/tour) – RiggsFolly Sep 17 '18 at 10:11
  • `file_get_contents() ` return string, so you should `json_decode()` the file content – mssb Sep 17 '18 at 10:20

1 Answers1

2

1.You need to decode your json first using json_decode()

2.You need to use $value instead of $someObject->matches in the second foreach()

$someObject = file_get_contents("http://varzesht.com/my/live.php");
$array_data = json_decode($someObject); //decode json data and assign it to a new variable
foreach($array_data as $value) { // use that new variable to iterate
    echo $value->stage_name;
    foreach($value->matches as $val) { // use $value here
        echo $val->home_team->start_time . "<br>". $val->home_team->name;
    }
}
Alive to die - Anant
  • 70,531
  • 10
  • 51
  • 98