php-static variables

A static variable retains its value between calls to a function but is visible only within that function.
IT declare a variable static with the static keyword.

function test_counter (  ) {
  static $counter = 0;
  $counter++;
  echo "Static counter is now $counter\n";
}
$counter = 5;
test_counter(  );
test_counter(  );
echo "Global counter is $counter\n";
Static counter is now 1
Static counter is now 2
Global counter is 5
 
Variables declared outside a function are global.
 That is, they can be accessed from any part of the script. By default, 
they are not available inside functions.
Related Posts:
  • php job in kolkata Learn web design & development with sitepoint tutorials, courses and books -  html5, css3, javascript, php, mobile app development, responsive web design.  In-depth tanking class/job analysis - tutorials and … Read More
  • Abstract data type In programming, a data set defined by the programmer in terms of the information it can contain and the operations that can be performed with it. An abstract data type is more generalized than a data type constr… Read More
  • Php for-web developers   PHP MySQL Functions Free Hosting Requiring Cookies Web Application with PHP php -Mail Functions PHP Array Substrings PHP Comparison Operators for If/Else Statements Showing the Browser and I… Read More
  • PHP-Session Security Because a session may contain sensitive information, you need to treat the session as a possible security hole. Session security is necessary to create and implement a session. If someone is listening in or snoop… Read More
  • php mvc tutorial for beginners-Model-View-Controller In most PHP web applications, you won’t have a strict MVC setup. In fact, it’s quite a lot of work to go full-on MVC with PHP. Getting a web project off the ground can be cumbersome and technically demanding, especially … Read More
  • Database Functions-PHP MySQL PostgreSQL MS SQL (Microsoft) Chances are good that you will have at least one of these databases available to you (very good since MySQL and PostgreSQL are available for free download). There are four… Read More
  • php.ini Basics After you have compiled or installed PHP, you can still change its behavior with the php.ini file. On Linux/UNIX systems, the default location for this file is /usr/local/php/lib or the lib subdirectory of the PHP installati… Read More
  • PHP Sessions The session_start( ) function is used to create a new session. A session is unique to the interaction between a browser and a web database application. If you use your browser to access several sites at once, you'll hav… Read More
  • Advanced Database Job PHP PHP supports the following databases in one form or another: MySQL— www.mysql.com mSQL— www.hughes.com.au MS SQL (Microsoft SQL server; on Win32 systems only) filePro (Read only)— www.fptech.com Informix— (fr… Read More
  • PHP Tutorial PHP Functions Php tutorial - imagemagick php.ini Basics PHP Sessions Cookies Versus Sessions PHP Web-Related Variables PHP ERRORS maximum size of a file uploaded Php Image upload php file_get_conte… Read More
  • PHP-simple Form Since you'll need a place for the user to enter a search query, let's begin by building a form to handle the user's input. Every form must have these basic components:The submission type defined with the met… Read More
  • PHP's variable-related functions PHP's variable-related functions are a key part of the language. Skilled programmers rely on them extensively to build robust code that uses type-checking. Functions like var_dump() and print_r() are also invaluable w… Read More
  • PHP-Database-Basics-DB-Arrays Adding MySQL to PHP and combining the applications for your dynamic web site is a great start. But, it helps tremendously to structure your database right. We'll give you a solid understanding of both database de… Read More
  • PHP-Associative Array When you are building an ordinary array, the array function requires the data, but doesn't require you to specify the indices. It automatically generates the index of each element by grabbing the next available intege… Read More
  • mysql_fetch_array-code-demo  Example-1  mysql_fetch_array  code demo <?php//error_reporting(0); session_start(); include "include/connection.php"; include "include/functions.php"; if(@$_REQUEST['act']=='… Read More