You often need PHP scripts that you need to use over and over. Here are a couple.
Calculate Execution Time.
This is useful for calculating the time a script took to execute. This is helpful for debugging purposes.
//Create a variable for the start time
$time_start = microtime(true);// Place your other code you need here
//Create a variable for the end time
$time_end = microtime(true);//Subtract the two times to get seconds
$time = $time_end – $time_start;echo ‘Script took ‘.$time.’ seconds to execute’;
Add (th,st,nd,rd) to the end of a number.
Do you need your 1 to say 1st and your 2 to say 2nd? Then this is for you.
function make_ranked_num($rank) {
$last = substr( $rank, -1 );
$seclast = substr( $rank, -2, -1 );
if( $last > 3 || $last == 0 ) $ext = ‘th’;
else if( $last == 3 ) $ext = ‘rd’;
else if( $last == 2 ) $ext = ‘nd’;
else $ext = ‘st’;if( $last == 1 && $seclast == 1) $ext = ‘th’;
if( $last == 2 && $seclast == 1) $ext = ‘th’;
if( $last == 3 && $seclast == 1) $ext = ‘th’;return $rank.$ext;
}
We will post more soon. I hope that helps.
