0

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 table would be appropriate. Convert [digit] to <tr> and [name] to <td>, then surround with <table> tag and clean up. Commented Jan 4, 2010 at 4:41
  • 1
    You could possibly explain a bit better:)? Need the value of the name value. Or any value and not key? Commented Jan 4, 2010 at 4:45
  • I was suggesting that [a single digit] could be replaced by <tr> and [a name or word] could be replaced by <td>. I see several of those in the web page source. A fair bit of cleaning up would be necessary to get a clean <table>, but the array looks like a table to me. Commented Jan 4, 2010 at 4:53

3 Answers 3

3

Looks like a print_r() output to me.

Sign up to request clarification or add additional context in comments.

1 Comment

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.
1

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

Comments

0

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'

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.