/ Published in: PHP
                    
                                        
                            
                                Expand |
                                Embed | Plain Text
                            
                        
                        Copy this code and paste it in your HTML
function tally($ns = null, $setTo = null) {
if ($ns === null) {
return $tallies;
}
if ($setTo) {
$tallies[$ns] = $setTo;
return;
}
$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 )
Comments
 Subscribe to comments
                    Subscribe to comments
                
                