#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Posts
    51
    Rep Power
    15
    How do I pass a varible from a function to global?

    Thanks, Charlie...
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Location
    London/UK
    Posts
    91
    Rep Power
    15
    a) you could return it

    <?
    function something() {
    $thing = "3";
    return $thing;
    }

    $mything = somthing();
    ?>

    b) use an internal globals definition

    <?
    function something() {
    global $thing;
    $thing = "3";
    }

    something();

    print $thing;
    ?>
    c) use the $GLOBALS[] var

    <?
    function something() {
    $GLOBALS["thing"] = "3";
    }

    print $thing;
    ?>

    this does rely that the register_globals is switched to 'On' in php.ini

    hth

    Bealers

    [This message has been edited by Bealers (edited August 07, 2000).]

Similar Threads

  1. Uploading Files
    By vivekjain in forum ASP Programming
    Replies: 0
    Last Post: February 16th, 2004, 11:21 PM
  2. passing checkbox 'name' into a function?
    By jreider in forum HTML Programming
    Replies: 3
    Last Post: February 15th, 2004, 08:30 PM
  3. passing a form's select name into a javascript function
    By kilt88 in forum JavaScript Development
    Replies: 1
    Last Post: January 6th, 2004, 01:12 PM
  4. Passing arrays to function
    By aiya in forum HTML Programming
    Replies: 1
    Last Post: December 19th, 2003, 12:35 PM
  5. Replies: 6
    Last Post: December 19th, 2003, 02:00 AM

IMN logo majestic logo threadwatch logo seochat tools logo