tags:

views:

63

answers:

3

Using PHP, how do I output/display the values from this array within my web page:

http://api.getclicky.com/api/stats/4?site_id=83367&sitekey=e09c6cb0d51d298c&type=clicks&output=php&unserialize

+3  A: 

Looks like a print_r() output to me.

aib
I don't believe he asked how to output the data like this... He wanted to know how to output the data into a web page. I assumed he used the print_r statement to display the data structure.
DeveloperChris
+1  A: 

Use a foreach statement to iterate over the array echoing each as you go

foreach($data as $k => $v) {
  echo "{$k} => {$v}";
}

$data is the input data $k is the key $v is the $value

The above is only useful for a single depth array for an array of arrays like the example data provided you need to use a recursive function then check to see if the value is an array if so call the function recursivally.

If the data structure never changes then some nested loops will do the job. (some people think recursion is evil, I pity them)

DC

DeveloperChris
A: 

Start with our Array

$myarray = array(
  "Key1" => "This is the value for Key1",
  "Key2" => "And this is the value for Key2"
);

Show All Output (Helpful for Debugging)

print_r($myarray);
/* or */ 
var_dump($myarray);

Show only a Single Value

print $myarray["Key1"]; // Prints 'This is the value for Key1'
print $myarray[0]; // Prints 'This is the value for Key1'
Jonathan Sampson