SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict chartahir's Avatar
    Join Date
    Oct 2006
    Location
    Karachi, Pakistan
    Posts
    253
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Function return values ???

    How can i return two values from a function, do i 've to implement using classes or it can be done other way ???
    chartahir

  2. #2
    SitePoint Addict phpster's Avatar
    Join Date
    Feb 2005
    Location
    Toronto, Canada
    Posts
    374
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    array? or concatenate a string ? both are workable
    phpster

    I wish my computer would do what I want it to.
    Not what I tell it to do...

  3. #3
    SitePoint Guru brent5392's Avatar
    Join Date
    Dec 2005
    Location
    Australia
    Posts
    636
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    function myfunction() {
    $myarray = array('value1' => 'thisisvalueone''value2' => 'thisisvaluetwo');
    return 
    $myarray;
    }
    $result myfunction();
    echo 
    $result['value1']; // outputs 'thisisvalueone'
    echo $result['value2']; // outputs 'thisisvaluetwo' 
    That should work provided i didnt make any typos
    PHP | MySQL | (X)HTML | CSS

  4. #4
    SitePoint Enthusiast
    Join Date
    Sep 2005
    Posts
    75
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    u can pass the variable by reference

  5. #5
    SitePoint Addict pkSML's Avatar
    Join Date
    Aug 2006
    Location
    Ohio
    Posts
    230
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Do you need a return value?

    If you're returning a string or number, you can do something else.
    You can initialize a variable in the global scope. Then call it in your function ( global $variable; ), and set it's value inside the function.
    -Stephen

    Get a LitlURL to this page!


Bookmarks

Posting Permissions

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