SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Guru DeNasio's Avatar
    Join Date
    May 2001
    Posts
    830
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    global variables

    If I define a variable $var, and then define a function Func(), then I can't use the variable $var inside the function because the variable is defined outside the function. If I want to use the variable $var inside the function, then I have to send it as a parameter in the function header like this, Func($var).

    But the problem is that I have many global variables, and many functions. I don't want to pass all these variables to all the functions!

    Isn't there a way that the functions can recognize my global variables without sending these variables as parameters in the function headers?

    Please advice.

  2. #2
    Mlle. Ledoyen silver trophy seanf's Avatar
    Join Date
    Jan 2001
    Location
    UK
    Posts
    7,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Use global inside the function. For example:
    PHP Code:
    global $myvar1$myvar2
    Sean
    Harry Potter

    -- You lived inside my world so softly
    -- Protected only by the kindness of your nature

  3. #3
    SitePoint Guru
    Join Date
    Jan 2001
    Location
    Alkmaar, Netherlands
    Posts
    710
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    u ask for advice and I see that u get the answer in 4 minutes but there is faster method for this kind of base questions: www.php.net
    just enter global in search box and search whole site. Look at the top link. Fast huh?

  4. #4
    Mlle. Ledoyen silver trophy seanf's Avatar
    Join Date
    Jan 2001
    Location
    UK
    Posts
    7,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, but it is nice to talk to people!

    Sean
    Harry Potter

    -- You lived inside my world so softly
    -- Protected only by the kindness of your nature


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
  •