PHP

Variable scope in functions and files


Variable scope, scope inside functions.

Scope of variables inside and out a function

Scope example of the variables.

<?php 

function display_info(){
    $username =  "user_01";
    echo "Value of \$username inside the function is: ".$username;
}

$username = "user_250"; // variable with file scope


echo $username. "<br>";  // Displays "user_250";


display_info(); // Displays  "user_01"