Return to Snippet

Revision: 30844
at August 24, 2010 00:13 by feeela


Initial Code
function numerals($number)
{
	if(strlen($number) > 1 && 1 == substr($number, -2, -1))
	{
		$lastDigit = 0;
	}
	else
	{
		$lastDigit = substr($number, -1);
	}

	switch($lastDigit)
	{
		case 3:
			$numeralAppendix = 'rd';
			break;
		case 2:
			$numeralAppendix = 'nd';
			break;
		case 1:
			$numeralAppendix = 'st';
			break;
		default:
			$numeralAppendix = 'th';
			break;
	}
	return $number . $numeralAppendix;
}

Initial URL
http://snipplr.com/view/39427/make-position-number/

Initial Description


Initial Title
alternative notation of "Make Position Number", using less if-statements

Initial Tags


Initial Language
PHP