Jump to content


Photo

Array


  • Please log in to reply
4 replies to this topic

#1 willpower

willpower
  • Members
  • PipPipPip
  • Advanced Member
  • 296 posts
  • LocationWarrington, Cheshire, UK

Posted 02 March 2006 - 02:18 PM

if I have an array $result

how do I echo all the contents?

$result[1], $result[2]..etc
Wait...I've got it...Bollocks, it's gone again!

If at first you don't succeed....stop using ASP and get onto PHP

#2 marker5a

marker5a
  • Members
  • PipPipPip
  • Advanced Member
  • 30 posts

Posted 02 March 2006 - 02:27 PM

print_r($array) works great for me

or...

You could also do

foreach($array as $value)
{
echo "$value, ";
}

#3 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 02 March 2006 - 02:33 PM

[!--quoteo(post=350959:date=Mar 2 2006, 09:27 AM:name=marker5a)--][div class=\'quotetop\']QUOTE(marker5a @ Mar 2 2006, 09:27 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
print_r($array) works great for me
[/quote]

yep, and it's really helpful to put it within <pre> tags, too:

echo "<pre>\n";
print_r($array);
echo "</pre>\n";

You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx

#4 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 02 March 2006 - 03:07 PM

You can do the last suggestion in one line:
<?php echo '<pre>'.print_t($array,true).'</pre>'; ?>

Ken

#5 willpower

willpower
  • Members
  • PipPipPip
  • Advanced Member
  • 296 posts
  • LocationWarrington, Cheshire, UK

Posted 02 March 2006 - 05:01 PM

Thank you all...
Wait...I've got it...Bollocks, it's gone again!

If at first you don't succeed....stop using ASP and get onto PHP




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users