This seems like such a rookie question but I'm just banging my head against the keyboard here and I can't find anything answered already that gets me moving forward.
This is my PHP:
<?php
header('Content-Type: text/plain; charset=utf-8;');
$url = file_get_contents("https://example.org/subdomain/api.php?t=t&q=maria");
print_r(json_decode($url));
?>
This is the results:
stdClass Object
(
[apiVersion] => 1
[data] => Array
(
[0] => stdClass Object
(
[id] => 47
[by] => 5
[title] => WATER
...
)
[1] => stdClass Object
(
[id] => 45
[by] => 5
[title] => HEARTH
...
)
...
How could I extract and echo the property title?
I tried this without success (error 500, blank page)
<?php
header('Content-Type: text/plain; charset=utf-8;');
$url = 'https://example.org/subdomain/api.php?t=t&q=maria';
$json = file_get_contents($url);
$answersArray = Array();
for($i=0;$i<count($jsonArray['data']);$i++){
array_push($answersArray,$jsonArray['data'][$i]['title']);
}
UPDATE
I tried also with this code, still no luck
<?php
header('Content-Type: text/plain; charset=utf-8;');
$url = 'https://example.org/subdomain/api.php?t=t&q=maria';
$json = file_get_contents($url);
$answersArray = Array();
for($i=0;$i<count($jsonArray['data']);$i++){
array_push(echo $answersArray,$jsonArray['data'][$i]->title);
}
foreach($answersArray as $answer) {
echo $answer;
}
?>
data3) Return the property title for each object:$titles = array_map(function($v){return $v->title;}, json_decode($json)["data"]);$json = file_get_contents($url); $data = json_decode($json); foreach($data as $key => $subarray) { $titles = array_map(function($v){return $v->title;}, json_decode($json)["data"]); }ini_set("display_errors", 1); error_reporting(E_ALL);at the top of your file(s) and tell us if you get any + check your error logs and tell what you get. (Also what is the output of:echo PHP_VERSION;?)