Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11
  1. #1
    Regular Coder
    Join Date
    Aug 2006
    Location
    UK, London, Dartford
    Posts
    221
    Thanks
    3
    Thanked 14 Times in 14 Posts

    Simple Question (print_r)

    Why when you use print_r a '1' appears at the end?

    Just a weird question just bugging me to find out.
    Last edited by Lee Stevens; 03-08-2009 at 12:52 AM.

  • #2
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by Lee Stevens View Post
    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

  • #3
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    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.
    PHP Code:
    $var true;
    print_r($var); // 1 
    For example.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #4
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,049
    Thanks
    2
    Thanked 317 Times in 309 Posts
    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.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #5
    Regular Coder
    Join Date
    Aug 2006
    Location
    UK, London, Dartford
    Posts
    221
    Thanks
    3
    Thanked 14 Times in 14 Posts
    Well i'm mysql_fecth_assoc then print_r($result)

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

  • #6
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,049
    Thanks
    2
    Thanked 317 Times in 309 Posts
    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.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #7
    Regular Coder
    Join Date
    Feb 2005
    Posts
    663
    Thanks
    5
    Thanked 14 Times in 14 Posts
    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.

  • #8
    Regular Coder
    Join Date
    Aug 2006
    Location
    UK, London, Dartford
    Posts
    221
    Thanks
    3
    Thanked 14 Times in 14 Posts
    PHP Code:
        $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); 
    Code:
    <p><b>Discussions:</b><? echo print_r($discussions['ds_title']); ?></p>

  • #9
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by Lee Stevens View Post
    PHP Code:
        $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); 
    Code:
    <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

  • #10
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Quote Originally Posted by oesxyl View Post
    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.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #11
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by Fou-Lu View Post
    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:
    PHP Code:
    echo print_r($myarraytrue); 
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •