Мне нужно показать на странице некоторые данные из json_decode, но я получаю ошибку недопустимого смещения.
$json = '{"result":{"keyword":"seo",
"cost":0.54,
"concurrency":25,
"found_results":422000000,
"region_queries_count":1900,
"region_queries_count_wide":0,
"region_queries_count_phrase":0,
"types":["related_search","pic"],
"geo_names":[],
"social_domains":["wikipedia","linkedin"],
"right_spelling":null,
"keyword_length":1,
"lang":null,
"keyword_id":"647713",
"suggestions_count":12528,
"keywords_count":1637
},
"status_msg":"OK",
"status_code":200,
"left_lines":99787
}';
$obj = json_decode($json, true);
if (is_array($obj['result'])) {
foreach ($obj['result'] as $keywords) {
echo '<li>Keyword: "'.$keywords['keyword'].'", Adwords CPC: <b>'.$keywords['cost'].'</b> USD, Concurrency: <b>'.$keywords['concurrency'].'</b>, Results: <b>'.$keywords['found_results'].'</b>, Search Volume: <b>'.$keywords['region_queries_count'].'</b>.</li>'.PHP_EOL;
echo '</ol>';
}
}
var_dump($obj) return:
array(4) { ["result"]=> array(16) { ["keyword"]=> string(3) "seo" ["cost"]=> float(0.54) ["concurrency"]=> int(25) ["found_results"]=> int(422000000) ["region_queries_count"]=> int(1900) ["region_queries_count_wide"]=> int(0) ["region_queries_count_phrase"]=> int(0) ["types"]=> array(2) { [0]=> string(14) "related_search" [1]=> string(3) "pic" } ["geo_names"]=> array(0) { } ["social_domains"]=> array(2) { [0]=> string(9) "wikipedia" [1]=> string(8) "linkedin" } ["right_spelling"]=> NULL ["keyword_length"]=> int(1) ["lang"]=> NULL ["keyword_id"]=> string(6) "647713" ["suggestions_count"]=> int(12528) ["keywords_count"]=> int(1637) } ["status_msg"]=> string(2) "OK" ["status_code"]=> int(200) ["left_lines"]=> int(99791) }