PHP: Function that remembers a value using Global

Start PHP Code RESULT

1. Widgets

We build a fine range of widgets

2. Doodads

Finest in the world

End PHP Code RESULT

 

The PHP Code START
<?php
$num_of_calls = 0;
function numberedHeading( $txt ) {
  global $num_of_calls;
  $num_of_calls++;
  print "<h1>$num_of_calls. $txt</h1>";
}
numberedHeading("Widgets");
print("We build a fine range of widgets<p>");
numberedHeading("Doodads");
print("Finest in the world<p>");
?>
The PHP Code END

Back to Bill's PHP