Justin Erswell
Justin Erswell

Reputation: 708

Google Analytics Array decode foreach

Hi this is my first foray into the wonderful world of Google Analytics and their API and I have hit a road bump and wondered if someone could help.

I am retrieving the following array:

[
    [
     "iPhone",
     "United Kingdom",
     "51.5073",
     "-0.1277",
     "1",
     "18"
    ],
    [
     "iPhone",
     "Australia",
     "-33.8675",
     "151.2070",
     "1",
     "17"
    ],
    [
     "iPhone",
     "United Kingdom",
     "51.5171",
     "-0.1461",
     "5",
     "16"
    ]
]

this is being output to my page using the standard (demo based htmlOutput function) I am getting the data using this call in the

coreReportingApiReference.php

PHP:

  private function getRows($results) {
    $json;
    if(count($results->getRows()) > 0) {
        $json .= json_encode($results->getRows());
    } else {
        $json .= '<p>No results found.</p>';
    }
        return $json;
  }

I want to know how to - in a foreach loop get hold of each one of these objects in the outputted "array" and work with them in my page. At this point eve just running a count() on the output is return only 1.

My end goal is to use this data in a map overlay and some charts.

Thanks in advance for your advice.

Upvotes: 0

Views: 202

Answers (1)

Barmar
Barmar

Reputation: 780798

Something like this:

foreach($data as $row) {
  list($item, $country, $lat, $long, $number1, $number2) = $row;
  echo "$item was purchased in $country, at $lat x $long, with data $number1 and $number2\n";
}

Upvotes: 2

Related Questions