Keywords in PHP

Total Post:113

Points:791
PHP
 328  View(s)
Ratings:
Rate this:

What type of keywords in php ?

  1. Post:140

    Points:984
    Re: Keywords in PHP

    Keywords in PHP :

    1. Local: 

    <?php 
    $x = 20;
    $y = 40;
    function mindstick() {
        local $x, $y;
        $y = $x + $y;
    }
    mindstick();
    echo $y; // outputs 60
    ?>

    2. global: global variable access by using this from within a function. 

    Example: 

    <?php 
    $x = 5;
    $y = 10; 
    function mindstick() {
        $GLOBALS['y'] = $GLOBALS['x'] + $GLOBALS['y'];
    }
    mindstick();
    echo $y; // outputs 15
    ?>


    3. static:   all of its variables are deleted when a function is executed. 

    <?php 
    function mindstick() {
        static $x = 0;
        echo $x;
        $x++;
    }
    mindstick();
    mindstick();
    mindstick();
    ?>

Answer