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 3 of 3
  1. #1
    New Coder
    Join Date
    Jan 2013
    Location
    India
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How to define Variable Scope in Php?

    If you define a variable within a function that means variable is only available within that function. This variable cannot CALL in another function or in the body of your program code. These types of variable are known as a variable's scope. The scope of a variable defined within a function is local to that function. If you want to use variable that is defined in the main body of program code. Remember It must reference using global keyword.
    <?php
    function_SubNumber ( )
    {
    global $sum = 4 - 4
    }

    $sum = 0
    Subnumber ( )
    echo "4 - 4 = ".$sum
    ?>

  • #2
    New Coder
    Join Date
    Dec 2012
    Location
    USA
    Posts
    82
    Thanks
    3
    Thanked 17 Times in 17 Posts
    You're not really asking anything - or anything that is clearly a question.

  • #3
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Quote Originally Posted by TFlan View Post
    You're not really asking anything - or anything that is clearly a question.
    Not only that, they are showing code that promotes *very* sloppy programming practices.

    So to actually answer your question: scope is defined by the context in which you have declared your variables.

    The code itself, is completely useless. The function signature is incorrect, it has no semi-colon delimiters, and the use of global is entirely incorrect (global is *not* an assignment operation). So many a syntax errors this has.

    This does kind of raise question as to why this thread was posted in the first place though. . .
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 


  •  

    Tags for this Thread

    Posting Permissions

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