Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7550747
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T10:17:41+00:00 2026-05-30T10:17:41+00:00

Does anyone know a solution to this? I’d like to display the sum of

  • 0

Does anyone know a solution to this?

I’d like to display the sum of the different values with PHP. Something like:

Page post: (Sum of all)

Fan: (Sum of all)

User Post: (Sum of all)

….

Here is the JSON form the Facebook Graph APi.

{
  "data": [
    {
      "id": "SOME_ID/insights/page_stories_by_story_type/days_28", 
      "name": "page_stories_by_story_type", 
      "period": "days_28", 
      "values": [
        {
          "value": {
            "page post": 357, 
            "fan": 229, 
            "user post": 84, 
            "question": 72, 
            "mention": 4
          }, 
          "end_time": "2012-01-22T08:00:00+0000"
        }, 
        {
          "value": {
            "page post": 356, 
            "fan": 229, 
            "user post": 85, 
            "question": 73, 
            "mention": 4
          }, 
          "end_time": "2012-01-23T08:00:00+0000"
        }, 
        {
          "value": {
            "page post": 401, 
            "fan": 231, 
            "user post": 88, 
            "question": 73, 
            "mention": 4
          }, 
          "end_time": "2012-01-24T08:00:00+0000"
        }, 

      ], 
      "title": "28 Days Page Stories by story type", 
      "description": "28 Days The number of stories about your Page by story type. (Total Count)"
    }
  ], 
  "paging": {
    "previous": "https://SOME_LINK", 
    "next": "https://SOME_LINK"
  }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T10:17:43+00:00Added an answer on May 30, 2026 at 10:17 am

    I am not sure why, but the json you provided is not being decoded using standard json_decode, so I had to use a custom function found on http://php.net/manual/en/function.json-decode.php

    This is the code:

    function jsonDecode($json) {
    $comment = false;
    $out = '$x=';
    
    for ($i = 0; $i < strlen($json); $i++) {
        if (!$comment) {
            if (($json[$i] == '{') || ($json[$i] == '['))
                $out .= ' array(';
            else if (($json[$i] == '}') || ($json[$i] == ']'))
                $out .= ')';
            else if ($json[$i] == ':')
                $out .= '=>';
            else
                $out .= $json[$i];
        }
        else
            $out .= $json[$i];
        if ($json[$i] == '"' && $json[($i - 1)] != "\\")
            $comment = !$comment;
     }
     eval($out . ';');
     return $x;
    }
    
    // decode the JSON result
    $result = jsonDecode($json);
    
    $values = $result['data'][0]['values'];
    
    $total_values = array();
    
    // loop through the returned values to compute the sum for each property
    foreach ($values as $item) {
       foreach ($item['value'] as $key => $value) {
           if (isset($total_values[$key])) {
               $total_values[$key] += $value;
           } else {
               $total_values[$key] = $value;
           }
       }
    }
    
    print_r($total_values);
    

    The result is something like this:

    Array
    (
        [page post] => 1114
        [fan] => 689
        [user post] => 257
        [question] => 218
        [mention] => 12
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does anyone know a solution to this problem? I'm unable to open a subdirectory
Does anyone know the best solution for this? When i resize my browser some
Does anyone know of a solution for this that i may be able to
Does anyone know a good solution for implementing a function similar to Ruby's timeout
Does anyone know of a solution to the following markup validation error? I'm not
Does anyone know how to move the Solution Explorer tab in Visual Studio 2005?
Does anyone know a cross-browser, reliable solution for catching presses of the tab-key in
I'd like to add spaces between bars in ggplot2. This page offers one solution:
As title says, this issue happens in MS Access 2003 SP1. Does anyone know
Does anyone know the solution for working with XML in Java that meets these

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.