Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Local Variable

A local variable is a variable in a method or a function. It is in the local scope, and is not available anywhere else.

A local variable is created by assigning it a value in a method, using the static keyword, or using the extract() function. It might be removed by the unset() function.

<?php

    function foo() {
        $localVariable = 1;
        // ... more code
    }
    
    function goo() {
        // this variable is distinct from the one in foo()
        $localVariable = 2;
        // ... more code
    }

?>

Documentation

See Also