...

View Full Version : Resolved Simple Question (print_r)



Lee Stevens
03-07-2009, 08:57 PM
Why when you use print_r a '1' appears at the end?

Just a weird question just bugging me to find out.

oesxyl
03-07-2009, 09:02 PM
Why when you use print_r a '1' appears at the end?

Just a weird question just bugging me to find out.
it's the return code

best regards

Fou-Lu
03-07-2009, 09:02 PM
It doesn't there has to be something else thats inside of it. I don't know for certain what the 'r' stands for, but I always go by recursive since it does provide a string representation of arrays and objects.
If there is a 1 there, I'd be inclined to think that whatever you're printing has a true value in it.


$var = true;
print_r($var); // 1

For example.

CFMaBiSmAd
03-07-2009, 09:02 PM
No it does not, you must have something else in your code that is outputting a 1

You would need to post your code to get any specific help with what it is doing.

Lee Stevens
03-07-2009, 09:06 PM
Well i'm mysql_fecth_assoc then print_r($result)

Prints what in the array but adds a 1 at the end.

CFMaBiSmAd
03-07-2009, 09:20 PM
Can't help you with out seeing the actual code responsible for the symptom. You are printing/echoing something after that point in your code.

ptmuldoon
03-07-2009, 09:21 PM
I think its because the same variable name is being used more than once. Make sure the the same name is not being used elsewhere in the code.

Lee Stevens
03-07-2009, 09:26 PM
$query = "SELECT ds_title FROM tbl_discussions WHERE pj_id = '$pj_id'";
$result = mysql_query($query, $connection) or die("Unable to run query on database");
$discussions = mysql_fetch_assoc($result);



<p><b>Discussions:</b><? echo print_r($discussions['ds_title']); ?></p>

oesxyl
03-07-2009, 09:29 PM
$query = "SELECT ds_title FROM tbl_discussions WHERE pj_id = '$pj_id'";
$result = mysql_query($query, $connection) or die("Unable to run query on database");
$discussions = mysql_fetch_assoc($result);



<p><b>Discussions:</b><? echo print_r($discussions['ds_title']); ?></p>
as I said, 1 is the value echoed as return value of print_r, :)

best regards

Fou-Lu
03-07-2009, 09:43 PM
as I said, 1 is the value echoed as return value of print_r, :)

best regards

You were correct.
If you're printing a print_r it will be true unless you've captured the print_r. This simply indicates a success.
Drop the echo, print_r will perform the output.

oesxyl
03-07-2009, 09:55 PM
You were correct.
If you're printing a print_r it will be true unless you've captured the print_r. This simply indicates a success.
Drop the echo, print_r will perform the output.
same effect:


echo print_r($myarray, true);

it's pretty old, php 4.3, but I discover it now in the manual, :)

http://www.php.net/manual/en/function.print-r.php

if I'm not wrong, last year was a thread with same question. :)

best regards



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum