Interview QuestionsCategory: PHPwhat is the static variable in php?
bestonetechnologies Staff asked 2 years ago

what is the static variable in php?

1 Answers
Best Answer
bestonetechnologies Staff answered 2 years ago

A static variable is that which will not lose its value and will still hold value when the function be called again.
Example:
<?php
function counter() {
  STATIC $count = 0;
  $count++;
  print $count;
  print “<br />”;
}
counter();
counter();
counter();
?>
<strong>Output:</strong>
1
2
3

Your Answer

17 + 20 =