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
    Regular Coder
    Join Date
    Jun 2009
    Posts
    351
    Thanks
    75
    Thanked 0 Times in 0 Posts

    Why dont i get an echo of 10 for this code

    Why dont i get an echo of 10 for this code

    PHP Code:
        function test() {
            
    $test 10;
        
        
    //echo "inside function echo " . $test; 
        
    global $test;
        }
        
    test();
    echo 
    $test;
    exit; 

  • #2
    Regular Coder
    Join Date
    May 2007
    Posts
    100
    Thanks
    16
    Thanked 11 Times in 11 Posts
    Put the global at the beginning of the function.

  • #3
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,978
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    See my explanation of the problem in your other 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
    •