Static variable - PHP Online
Form of PHP Sandbox
Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php
in the places where the PHP script should be executed.
Result of php executing
Full code of Static variable.php
- <?php
- function sumValues($a, $b)
- {
- static $count = 0;
- $count++;
- if($count > 2)
- {
- return false;
- }
- else
- {
- return [$a + $b, $count];
- }
- }
- print_r(sumValues(3, 4));
- echo '<br>';
- print_r(sumValues(6, 7));
- echo '<br>';
- print_r(sumValues(2, 5));
- echo '<br>';
- print_r(sumValues(1, 3));