Quantcast
Channel: PHP Freaks: PHP Help
Viewing all articles
Browse latest Browse all 13200

Learning PHP static scope

$
0
0

Hello everyone,

 

I'm on w3schools getting used to PHP, I'm having issue getting around the following:

 

<!DOCTYPE html>
<html>
<body>

<?php

function myTest()
{
static $x=0;
echo $x;
$x++;
}

myTest();
myTest();
myTest();

?> 

</body>
</html>

 

The result being 012?

 

if I take away one of the myTest(); its becomes 01?

Why on earth is this happening and what does the $x++ do? I've searched high and low for an answer to no avail.


Viewing all articles
Browse latest Browse all 13200

Trending Articles