SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    John 8:24 JREAM's Avatar
    Join Date
    Sep 2007
    Location
    Florida
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Passing a function variable to another function

    Hey guys.
    I hope I can reply if someone is able to answer me, my dad might turn off the internet in a little bit.

    I was wondering this.
    is there a way to do that and pass the hey() variable into the say()?

    PHP Code:
    function hey () {
    $hey '1';
    }

    function 
    say() {
    echo 
    hey() . ' test';

    I dont understand what return does, i tried return $hey.
    I own a php manual but can not solve this.
    Thank you

  2. #2
    SitePoint Guru
    Join Date
    Jul 2005
    Location
    Orlando
    Posts
    634
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    return is what you're looking for.

    PHP Code:
    function hey () {
    $hey '1';
    return 
    $hey;
    }

    function 
    say() {
    echo 
    hey() . ' test';


  3. #3
    SitePoint Addict
    Join Date
    Jul 2008
    Posts
    213
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You have to call say() so it can call hey(), and yes use return in hey().

  4. #4
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    PHP 5.3 Coolness
    PHP Code:
    function hey () {
        
    $hey '1';
        return function () use ( 
    $hey ) {
            echo 
    $hey' test';
        };
    };

    $say hey();
    $say(); 
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  5. #5
    John 8:24 JREAM's Avatar
    Join Date
    Sep 2007
    Location
    Florida
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok I understand thank you for this reply guys, i can play with this more and understand thing now thanks

    ps: that 5.3 php is very cool


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
  •