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 8513687
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T04:38:52+00:00 2026-06-11T04:38:52+00:00

I am looking for a way to output a multidimensional array as a simple

  • 0

I am looking for a way to output a multidimensional array as a simple table.

I got it by processing xml available here http://google.com/complete/search?output=toolbar&q=adam with the simple function

function convertXmlObjToArr($obj) { 
$json = json_encode($obj);
$array = json_decode($json,TRUE);

return $array;

}

and got an array

   array(1){ ["CompleteSuggestion"]=>
  array(10) {
    [0]=>
    array(1) {
      ["suggestion"]=>
      array(1) {
        ["@attributes"]=>
        array(1) {
          ["data"]=>
          string(12) "adam sandler"
        }
      }
    }
    [1]=>
    array(2) {
      ["suggestion"]=>
      array(1) {
        ["@attributes"]=>
        array(1) {
          ["data"]=>
          string(11) "adam levine"
        }
      }
      ["num_queries"]=>
      array(1) {
        ["@attributes"]=>
        array(1) {
          ["int"]=>
          string(8) "33200000"
        }
      }
    }
    [2]=>
    array(2) {
      ["suggestion"]=>
      array(1) {
        ["@attributes"]=>
        array(1) {
          ["data"]=>
          string(12) "adam carolla"
        }
      }
      ["num_queries"]=>
      array(1) {
        ["@attributes"]=>
        array(1) {
          ["int"]=>
          string(7) "5570000"
        }
      }
    }
    [3]=>
    array(2) {
      ["suggestion"]=>
      array(1) {
        ["@attributes"]=>
        array(1) {
          ["data"]=>
          string(12) "adam lambert"
        }
      }
      ["num_queries"]=>
      array(1) {
        ["@attributes"]=>
        array(1) {
          ["int"]=>
          string(8) "45400000"
        }
      }
    }
    [4]=>
    array(1) {
      ["suggestion"]=>
      array(1) {
        ["@attributes"]=>
        array(1) {
          ["data"]=>
          string(17) "adam sandler died"
        }
      }
    }
    [5]=>
    array(2) {
      ["suggestion"]=>
      array(1) {
        ["@attributes"]=>
        array(1) {
          ["data"]=>
          string(19) "adam sandler movies"
        }
      }
      ["num_queries"]=>
      array(1) {
        ["@attributes"]=>
        array(1) {
          ["int"]=>
          string(8) "43600000"
        }
      }
    }
    [6]=>
    array(2) {
      ["suggestion"]=>
      array(1) {
        ["@attributes"]=>
        array(1) {
          ["data"]=>
          string(13) "adam morrison"
        }
      }
      ["num_queries"]=>
      array(1) {
        ["@attributes"]=>
        array(1) {
          ["int"]=>
          string(8) "13800000"
        }
      }
    }
    [7]=>
    array(2) {
      ["suggestion"]=>
      array(1) {
        ["@attributes"]=>
        array(1) {
          ["data"]=>
          string(10) "adams golf"
        }
      }
      ["num_queries"]=>
      array(1) {
        ["@attributes"]=>
        array(1) {
          ["int"]=>
          string(8) "30500000"
        }
      }
    }
    [8]=>
    array(2) {
      ["suggestion"]=>
      array(1) {
        ["@attributes"]=>
        array(1) {
          ["data"]=>
          string(10) "adam yauch"
        }
      }
      ["num_queries"]=>
      array(1) {
        ["@attributes"]=>
        array(1) {
          ["int"]=>
          string(8) "19700000"
        }
      }
    }
    [9]=>
    array(2) {
      ["suggestion"]=>
      array(1) {
        ["@attributes"]=>
        array(1) {
          ["data"]=>
          string(9) "adam west"
        }
      }
      ["num_queries"]=>
      array(1) {
        ["@attributes"]=>
        array(1) {
          ["int"]=>
          string(9) "137000000"
        }
      }
    }
  }
}

Now I would like to output it and face 2 problems:

  1. How do I “dig into” the relevant information (“data” and “int”) in an array structured like this? So far I was dealing with much simpler arrays (not so “deep”).
    I am trying to for it via foreach loop

foreach($googleKeywords->CompleteSuggestion as $suggestion){

echo"{$this->suggestion->data}"; }

but keep getting “Trying to get property of non-object” error.

  1. As you notice some of the data is not complete – there is a name in “data” but not corresponding “int”… would be there a way to echo “no data” whether “int” is not set?

All the best,

Adam

  • 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-11T04:38:53+00:00Added an answer on June 11, 2026 at 4:38 am

    Thanks,

    The final code that worked involved nested loops and is as follows:

    <pre>foreach($keywords as $suggestion){
     foreach ($suggestion as $finalSuggestion){
       echo "<p>".$finalSuggestion['suggestion']['@attributes']['data']."</p>";
       echo $finalSuggestion['num_queries']['@attributes']['data']."<br/>";
        if (array_key_exists('num_queries', $finalSuggestion)) {
        echo "<p> ".$finalSuggestion['num_queries']['@attributes']['int']." </p>";
        }
        else
            {
            echo "<p>no data</p> ";
        }
         }
    
    }
    </pre>  
    

    PS. Sorry for the awful formatting of the code , still not sure how to do it properly here…. I usually just put < pre> but it goes wild now….

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm looking for a way to do simple aggregates / counts via data.table. Consider
I'm looking for a way to output a VERY simple pdf file from Python.
Looking for a way to add a couple of Simple XML objects together. The
I am looking for a way to output an instantiated class, an Object to
I am looking for a way to have output in the same manner as
I'm looking for a way to send the output of an arbitrary Emacs command
I am looking for a good, standard way to generate output in my RCP
I am looking for a way to read the standard output byte by byte
I'm looking for a way to include a few additional strings in output .java
I'm looking for a way to loop through the columns of a table to

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.