Skip to content

Instantly share code, notes, and snippets.

@tw2113
Created May 25, 2011 05:31
Show Gist options
  • Save tw2113/990405 to your computer and use it in GitHub Desktop.
Save tw2113/990405 to your computer and use it in GitHub Desktop.
Macho Man Randy Savage
<?php //RIP Randall Mario Poffo
function macho_man_randy_savage() {
static $elbow_drops = 3;
if(!$elbow_drops) return 'oooooooooooooooohhhhhhhhhhhhhhhh yeeeeeeeeeeeeeeeeaaaaaaaahhhhhh';
$elbow_drops--;
}
//will show phrase on 4th call and every call after.
echo macho_man_randy_savage();
?>
@IsaacVanName
Copy link

Yep. If you want it to show phrase on 3rd call, move the -- statement or start elbow_drops at 2.

Or, if you want more flexibility, you could have an optional argument that defaults to the starting amount, like this:

function slim_jim($total = 3) {
static $elbow_drops = $total;

// the rest
}

Then, you can call it as in the gist to start it at 3, or you could call slim_jim(10) to start it at 10.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment