Clean my plate, but keep my wine bottle. (PHP; Static)
On Monday morning, I served Colin's breakfast on a clean plate in the "Whitworth" ... one happy camper, judging by the crumbs and butter wrappers left on the plate, and the smile on Colin's face.
Never wanting to disturb a customer's property and space, I carefully preserved the plate as Colin left it on that morning and returned the plate to him, in that same crumby condition, on Tuesday morning. But Colin didn't appreciate the care I had taken to preserve his crumbs and would have much preferred a clean start.
On Wednesday, I'll make sure he has a clean, pristine new plate!
When you call a function in PHP, the internal variables within that function are freshly re-initialised each time. There is no debris left over from previous operations. And that's a good and sensible default - just like Colin on Tuesday and Wednesday morning, you don't want to be reminded about what happened on Monday.
Colin drank a glass of wine out of a bottle he brought with him on Tuesday night, and came looking for it to have another glass on Wednesday night. He was a little unhappy that we had cleaned up and thrown out his undrunk wine, even though he had requested a clean breakfast plate each morning. This is an exception to the "clean up fully every time" rule ... and in PHP terms, you would declare a variable within the function to be static to ensure that its value is held from one call to the next. (written 2007-09-18)
Associated topics are indexed as below, or enter http://melksh.am/nnnn for individual articlesH105 - PHP - Functions 
Coding efficiency - do not repeat yourself! - (2010-11-02) 
Passing a variable number of parameters in to a function / method - (2010-08-20) 
Improving your function calls (APIs) - General and PHP - (2010-04-24) 
Adding extensions to PHP Open Source applications - callbacks - (2010-03-17) 
Static variables and ampersands in PHP - (2010-02-10) 
A variable number of arguments in a PHP function - (2009-11-02) 
Global - Tcl, PHP, Python - (2008-09-03) 
Static variables in PHP - (2007-10-05) 
is there a lookup function in php? - (2007-07-15) 
Returning multiple values from a function (Perl, PHP, Python) - (2007-05-24) 
A better alternative to cutting and pasting code - (2007-04-26) 
PHP - static declaration - (2007-01-04) 
Global, Superglobal, Session variables - scope and persistance in PHP - (2006-11-21) 
A lazy programmer is a good programmer - (2006-09-15) 
Do not duplicate your code - (2006-06-23) 
Don't repeat code - use loops or functions - (2005-08-21) 
Functions and commands with dangerous names - (2005-08-11) 
Code and code maintainance efficiency - (2005-06-08) 
Passing information into and out of PHP functions - (2005-06-07) 
Call by name v call by value - (2005-05-11) 
There is a function in PHP to do that - (2005-02-21) 
Variable Scope - (2004-10-22)
Some other Articles
Korn shell courseAsda in Melksham - Welcome or not?Little Gems but not LettuceLook forward with a new broom - Wiltshire Train ServiceClean my plate, but keep my wine bottle. (PHP; Static)Crystal Ball - How long do I need to be online?.php or .html extension? Morally Static PagesMatch the Bedroom to the HotelMood shotsActionscript / Flash / Flex (IAQ/FAQ)