PHP STATIC VARIABLE EXAMPLE

  • PHP only supports static variables within the scope of a function definition
  • Static variables are, in fact, variable. The “static” means that the variable retains its value between calls to whatever that variable’s scope is (function, class, procedure, etc.)
  • Variables in PHP can only be static within the context of a function. Once a script exits, all variables are released. If you need to share variables between scripts, then you’ll need to either use sessions (I would think this would usually be the best solution), send them via form POST or GET data, or use a database for data persistence.

here is an example paste of static variable in PHP

you can see the output here

 

Advertisements