Return to Snippet

Revision: 39738
at January 20, 2011 07:00 by kendsnyder


Initial Code
function tally($ns = null, $setTo = null) {
	static $tallies = array();
	if ($ns === null) {
		return $tallies;
	}
	if ($setTo) {
		$tallies[$ns] = $setTo;
		return;
	}
	if (!isset($tallies[$ns])) {
		$tallies[$ns] = 0;
	}
	$tallies[$ns]++;
}
// Example usage
// foreach ($arr as $k => $v) {
//   tally('start of loop');
//   // code
//   if ($x) { continue; }
//   tally('end of loop');
// }
// print_r(tally()); // Array ( [start of loop] => 10, [end of loop] => 6 )

Initial URL

                                

Initial Description

                                

Initial Title
Count number of actions taken

Initial Tags
debug, Development

Initial Language
PHP