Skip to content

Instantly share code, notes, and snippets.

@afiore
Created May 29, 2011 13:39
Show Gist options
  • Save afiore/997788 to your computer and use it in GitHub Desktop.
Save afiore/997788 to your computer and use it in GitHub Desktop.
Caching a local variable in php
<?php
function uniqueId(){
static $id;
if (!isset($id)) {
$id=0;
} else {
$id++;
}
echo 'id_' . $id . "\n";
}
for($i = 0; $i < 10; $i++) {
uniqueId();
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment