В контроллере Cron я написал следующую функцию: -
public function football() {
$jsonData = file_get_contents('http://localhost/football/football/api/football_api.php');
}
$jsonData is returning the following object:-
stdClass Object
(
[callum-paterson] => stdClass Object
(
[id] => 1
[unique_id] => callum-paterson
[name] => Callum Paterson
[club] => Cardiff City
[position] => Defender
[national_team_name] => Unknown
[birthdate] => 1994-10-13
[birthplace] => Unknown
[nationality] => Unknown
[preferred_foot] => Unknown
[weight] => 76
[height] => 183
[shirt_number] => 13
[real_position] => Full Back
[real_position_side] => Right
[country] => Scotland
[photo_url] => https://img.footballindex.co.uk/callum-paterson-g-t1.jpg
)
[chicharito] => stdClass Object
(
[id] => 3
[unique_id] => chicharito
[name] => Chicharito
[club] => West Ham United
[position] => Forward
[national_team_name] => Unknown
[birthdate] => 1988-06-01
[birthplace] => Guadalajara
[nationality] => Mexico
[preferred_foot] => Right
[weight] => 73
[height] => 175
[shirt_number] => 17
[real_position] => Striker
[real_position_side] => Centre
[country] => Mexico
[photo_url] => https://img.footballindex.co.uk/javier-hernandez-g-t6.jpg
)
$ jsonData возвращает 1064 записи.Здесь я показываю несколько.поэтому я хочу напечатать все записи (например, id, unique_id, name и т. д.) внутри stdclass-object_index (например, [callum-paterson]).
Я новичок в JSON.Поэтому я не могу этого сделать.Любая помощь будет оценена.Я пробовал foreach, но он не работает.