Static variable in PHP -


if run following php code, 123. don't understand logic behind it. think when call function each time suppose output 1. output should 111.

function keep_track() {   static $count = 0;   $count++;   print $count; }  keep_track(); keep_track(); keep_track();  // output 123 

i know static variable holds value after function exits in above function assigning value in first line, yet still adding +1 previous value of $count.

could please explain this? (i sorry if sound stupid.. trying find out how happening)

$count initialized in first call of function , every time method called, increments $count.

in link, scroll down using static variables better understanding.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -