0

I am unable to fetch desired data of title, score from the json_decode array, I have tried all the ways which are already discussed in stackoverflow. Can anyone help me..

$myKEY = "xyz";
$url_req= 'google api request here';
$results= checkPageSpeed($url_req_d);
$googleapi = json_decode($results,true); 

Google api send the data like this when var_dump($googleapi) and I need to fetch title and score values from the array. Please reply suggested code to extract title and score values i.e "xyz" and "73"

{
 "kind": "pagespeedonline#result",
 "id": "www xyz com/",
 "responseCode": 200,
 "title": "xyz",
 "ruleGroups": {
  "SPEED": {
   "score": 73
  }
 },
 "pageStats": {
  "numberResources": 67,
  "numberHosts": 15,
  "totalRequestBytes": "9354",
  "numberStaticResources": 48,
  "htmlResponseBytes": "129210",
  "textResponseBytes": "5647",
  "cssResponseBytes": "142839",
  "imageResponseBytes": "411466",
  "javascriptResponseBytes": "635453",
  "otherResponseBytes": "94639",
  "numberJsResources": 17,
  "numberCssResources": 6
 },  .........
1
  • Where's your code fetching title and score ? Commented Mar 21, 2017 at 9:50

1 Answer 1

1

$googleapi['title'] and $googleapi['ruleGroups']['SPEED']['score'] should do the trick. Check the documentation for more information on how you can access elements from multidimensional arrays.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.