static means it's initiated only one time
output will be :
value of x inside sample is 1
value of x inside sample is 2
value of x inside sample is 3
<?php
function scope(){
echo "Value of x is ", $x;
}
//static means it's initiated only once
//first it's initiated by 0
function sample() {
static $x = 0;
$x = $x + 1;
echo "value of x inside sample is ", $x, "<br>";
}
sample();
sample();
sample();
output will be :
value of x inside sample is 1
value of x inside sample is 2
value of x inside sample is 3
<?php
function scope(){
echo "Value of x is ", $x;
}
//static means it's initiated only once
//first it's initiated by 0
function sample() {
static $x = 0;
$x = $x + 1;
echo "value of x inside sample is ", $x, "<br>";
}
sample();
sample();
sample();
No comments:
Post a Comment