Easy question, why does array() have bonus information..

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
timotheus
Forum Newbie
Posts: 6
Joined: Thu Oct 18, 2007 3:36 pm
Location: Berkeley, CA

Easy question, why does array() have bonus information..

Post by timotheus »

Hello,

So here is my issue.

Code: Select all

<?php
$output = array(1,2,3);
echo print_r($output);
?>
The output of this is:

Array ( [0] => 1 [1] => 2 [2] => 3 ) 1

Where is that extra '1' coming from? It's kind of driving me mad. :)

Thanks.
cpetercarter
Forum Contributor
Posts: 474
Joined: Sat Jul 25, 2009 2:00 am

Re: Easy question, why does array() have bonus information..

Post by cpetercarter »

To print out an array, all you need is print_r() - if you "echo" as well, you will get both the array and the value (1 or true) returned by the print_r() function.
User avatar
timotheus
Forum Newbie
Posts: 6
Joined: Thu Oct 18, 2007 3:36 pm
Location: Berkeley, CA

Re: Easy question, why does array() have bonus information..

Post by timotheus »

That makes a lot of sense. I forgot about that. Quite embarrassing. :roll:

I appreciate the quick response, many thanks.
Post Reply