Php program to print the variable using local variable function

Php program to print the variable using local variable function. In this program we can print the variable using local variable in php. Variables declared within a function are referred to as local variables in that function, and their scope is limited to that function. To put it another way, it can’t be accessible outside of that function.

<?php 
function local_var()
{
$num = 10;
echo $num;
}
local_var();
?>

 

Output:

10

What is local variable in php

Variables declared within a function are referred to as local variables in that function, and their scope is limited to that function. To put it another way, it can’t be accessed outside of that function. The scope of a variable refers to the area of the script where it can be referenced or used. There are three different variable scopes in PHP: local, global, and global.

Difference between single dollar and double dollar in php

$ and $$ Variables in PHP. The $var (single dollar) is a regular variable with the name var that can hold any value such as a string, integer, float, or other object. The $var (double dollar) is a reference variable that contains the $variable’s value.

An identifier for a simple value is a constant. During the script, the value cannot be changed. Constants, unlike variables, are always global across the entire script.