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 6 of 6

Thread: echo function?

  1. #1
    Regular Coder sitNsmile's Avatar
    Join Date
    Dec 2009
    Location
    Charlotte, NC
    Posts
    356
    Thanks
    19
    Thanked 2 Times in 2 Posts

    echo function?

    Okay trying to display all the variables in one function.

    Where I'd like to echo the entire function.
    PHP Code:
    echo $userData->collectUserData(); 
    PHP Code:
    public function collectUserData(){
            
            
    $this->getUserIp();
            
    $this->getUserBrowser();
            
    $this->getUserCountry();
            
    $this->getUserReferral();
            
            return 
    $this;
     
        } 
    and my results (output) just says "Object id #3"

    and if I do
    PHP Code:
    echo $userData->getUserIp(); 
    That works, but that's not what I want to do.

    Thanks
    Last edited by sitNsmile; 03-29-2010 at 07:54 PM.

  • #2
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    Code:
    public function collectUserData(){
            $array = array();
    
            $array[] = $this->getUserIp();
            $array[] = $this->getUserBrowser();
            $array[] = $this->getUserCountry();
            $array[] = $this->getUserReferral();
            
            return $array;
     
    }

  • #3
    Regular Coder
    Join Date
    Dec 2009
    Location
    UK
    Posts
    495
    Thanks
    0
    Thanked 58 Times in 58 Posts
    You could also implode the data into a string from the array that MattF has supplied so that the echo will display it all (perhaps using a <br /> as the glue)
    My site: JayGilford.com
    Resources:
    PHP Pagination Class | Getting all page links | Handling PHP Errors properly
    If you like a users help, show your appreciation with the rep and thanks buttons :)

  • #4
    Regular Coder sitNsmile's Avatar
    Join Date
    Dec 2009
    Location
    Charlotte, NC
    Posts
    356
    Thanks
    19
    Thanked 2 Times in 2 Posts
    Quote Originally Posted by MattF View Post
    Code:
    public function collectUserData(){
            $array = array();
    
            $array[] = $this->getUserIp();
            $array[] = $this->getUserBrowser();
            $array[] = $this->getUserCountry();
            $array[] = $this->getUserReferral();
            
            return $array;
     
    }
    every time I try this "array" out, no matter where I place it. all the output comes out is the word "Array"

  • #5
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    That's because it's ... an array. Pull the component using indexes 0, 1, 2, 3, or follow Jay's advice.
    Are you a Help Vampire?

  • #6
    Regular Coder
    Join Date
    Dec 2009
    Location
    UK
    Posts
    495
    Thanks
    0
    Thanked 58 Times in 58 Posts
    PHP Code:
    public function collectUserData(){
            
    $array = array();

            
    $array[] = $this->getUserIp();
            
    $array[] = $this->getUserBrowser();
            
    $array[] = $this->getUserCountry();
            
    $array[] = $this->getUserReferral();
            
            return 
    implode('<br />'$array);
     

    My site: JayGilford.com
    Resources:
    PHP Pagination Class | Getting all page links | Handling PHP Errors properly
    If you like a users help, show your appreciation with the rep and thanks buttons :)

  • Users who have thanked JAY6390 for this post:

    sitNsmile (03-29-2010)


  •  

    Posting Permissions

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