Note that there are some explanatory texts on larger screens.

plurals
  1. POArray with php for Json output
    primarykey
    data
    text
    <p>i'm trying to get the best practice to manipulate my array to get a json in a format similar to this one (better to work with charts)</p> <pre><code> { "serieMonth":["Aug-12","Sep-12","Oct-12","Nov-12","Dec-12","Jan-13","Feb-13"], "serieCA":[4214,10119,13325,12818,7177,20628,7664], "serieAdwordsCA":[0,0,0,0,0,310,332], "serieBooking":[10,28,46,34,17,51,16], "serieAdwords":[0,0,0,0,0,1,1], "serieTotalBooking":[10,28,46,34,17,52,17], "serieCartRepartition":[421,361,290,377,422,397,451], "serieTotalCart":[421,361,290,377,422,397,451] } </code></pre> <p>Actually my output looks like this :</p> <pre><code>[ {"date_year":"2012","date_month":"08","ad_cost":"0.0","ad_clicks":"0"}, {"date_year":"2012","date_month":"09","ad_cost":"0.0","ad_clicks":"0"}, {"date_year":"2012","date_month":"10","ad_cost":"0.0","ad_clicks":"0"}, {"date_year":"2012","date_month":"11","ad_cost":"0.0","ad_clicks":"0"}, {"date_year":"2012","date_month":"12","ad_cost":"44.9","ad_clicks":"43"}, {"date_year":"2013","date_month":"01","ad_cost":"297.56","ad_clicks":"462"}, {"date_year":"2013","date_month":"02","ad_cost":"82.5","ad_clicks":"103"} ] </code></pre> <p>And I'm using javascript to change it :</p> <pre><code>var xAxisLabels = new Array(), adClicks = new Array(), adCost = new Array(); $.each(data, function(i,v) { xAxisLabels.push(v["date_month"]+'/'+v["date_year"]); adCost.push(parseInt(v["ad_cost"])); adClicks.push(parseInt(v["ad_clicks"])); }); </code></pre> <p>I'm looking for the best way to do it in php since I get this data by the google api, here is my php.</p> <pre><code>// dimensions $dimensions = 'ga:year,ga:month'; $_params[] = 'date_year'; $_params[] = 'date_month'; // metrics $metrics = 'ga:adCost,ga:adClicks'; $_params[] = 'ad_cost'; $_params[] = 'ad_clicks'; $response = $service-&gt;data_ga-&gt;get('ga:' . $projectId, $from, $to, $metrics, array('dimensions' =&gt; $dimensions)); $analyticsStats = array(); foreach ($response['rows'] as $row) { $dataRow = array(); foreach ($_params as $colNr =&gt; $column) { $dataRow[$column] = $row[$colNr]; } array_push($analyticsStats, $dataRow); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload