Home >Backend Development >PHP Tutorial >Detailed explanation of how to use static static variables in st patrick day php
Take a look at the example below:
Copy code The code is as follows:
function Test()
{
$w3sky = 0;
echo $w3sky;
$w3sky++;
}
? >
Copy the code The code is as follows:
function Test()
{
static $w3sky = 0;
echo $w3sky;
$w3sky++;
}
?>
Copy code The code is as follows:
function Test()
{
static $count = 0;
$count++;
echo $count;
if ($count < 10) {
Test();
}
$count--;
}
?>
Copy code The code is as follows:
function foo(){
static $int = 0;// correct
static $int = 1+2; / / wrong (as it is an expression)
static $int = sqrt(121); // wrong (as it is an expression too)
$int++;
echo $int;
}
?>
The above introduces the detailed explanation of the use of static variables in st patrick day php, including the content of st patrick day. I hope it will be helpful to friends who are interested in PHP tutorials.