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

  • SEARCH
  • Home
  • 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 9062779
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T15:49:27+00:00 2026-06-16T15:49:27+00:00

I am making use of an available API to send requests and receive the

  • 0

I am making use of an available API to send requests and receive the results which is in json and xml formats. I am able to do so but how do I display the returned data properly?

I used json_decode and assign the xml data to an array and print_r those. It shows up in a huge junk of data.

How do I show it on a table form? Or must I save the data into individual files or database first before displaying?

I am new to PHP, thus not sure how to implement this.

  • 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-06-16T15:49:31+00:00Added an answer on June 16, 2026 at 3:49 pm

    JSON is a multidimensional-array, the easiest way to view it, in my opinion, is to just

    var_dump($json_array);
    

    Though, this may be the chunk of data you’re referring to.

    It’s not a very table friendly format, as a table is inherently 2-dimensional, and JSON can be many-dimensional.

    You can flatten the array, and then display it as a table.

    function flatten_json($json, &$flat, $key) {
    
        // First check the base case: if the arg is not an array,
        //   then it's data to be inserted in the flat array.
        if (!is_array($json)) {
            $flat[$key] = $json;
        } else {
    
            // It's an array, to reduce the depth of the json,
            // we remove this array, by iterating through it,
            // sending the elements to be checked if they're also arrays,
            // or if they're data to be inserted into the flat array.
    
            foreach ($json as $name => $element) {
                flatten_json($element, $flat, $key.'_'.$name);
            }
        }
    }
    

    To use this function, you first declare you flat array:

    $flat = array();
    

    Then pass it to the function, with your json, and a key you want to be the outer key, if you are sure that your json is an array, which is pretty much guaranteed, you can leave the key empty.

    flatten_json($json_array, $flat, '');
    

    Now $flat will have the flattened json, and you can print it as a table, maybe into a csv if you have many json results to print.

    If your json was:

    array(
        'person' => array(
            'name' => 'timmy',
            'age' => '5'
        ),
        'car' => array(
            'make' => 'ford',
            'engine' => array(
                'hp' => 260,
                'cyls' => 8
            )
         )
     )
    

    Then $flat will look like:

    array(
        'person_name' => 'timmy',
        'person_age' => 5,
        'car_make' => 'ford',
        'car_engine_hp' => 260,
        'car_engine_cyls' => 8
    )
    

    and if you wanted printed in a nice html table:

    echo "<table><tr>";
    foreach ($flat as $header => $value) {
        echo "<th>$header</th>;
    }
    
    echo "</tr><tr>";
    
    foreach ($flat as $header => $value) {
        echo "<td>$value</td>";
    }
    
    echo "</tr></table>";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am working on making bluetooth application which makes use of bluetooth api. i
I'm making use of an API on the internet that is marshalling objects to
I'm making use of the jQuery Tabs plugin along with the History plugin, to
We recently started making use of the new Google Expansion APK mechanism. Overall it
I am making use of a custom cursor on itemRenderers in a List component.
I am making use of django-registration and django-profile to handle registration and profiles. I
I'm making use of the extjs class objects through Ext.define (... and Ext.create (...
I am making use of a contenteditable div in combination with the rangy Javascript
I've been making use of callbacks to reduce coupling between some C++ classes. To
I have see some apps making use of the extra space you find when

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.