note 77609 deleted from ref.math by cmb

From: Date: Sun, 21 Jul 2019 09:03:01 +0000
Subject: note 77609 deleted from ref.math by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-211669@lists.php.net to get a copy of this message
Note Submitter: ddarjany at yahoo dot com ---- Tim's fix of Evan's ordinal function causes another problem, it no longer works for number above 100. (E.g. it returns 111st instead of 111th). Here is a further modified version which should work for all numbers. <?PHP function ordinal($cardinal) { $cardinal = (int)$cardinal; $digit = substr($cardinal, -1, 1); if ($cardinal <100) $tens = round($cardinal/10); else $tens = substr($cardinal, -2, 1); if($tens == 1) { return $cardinal.'th'; } switch($digit) { case 1: return $cardinal.'st'; case 2: return $cardinal.'nd'; case 3: return $cardinal.'rd'; default: return $cardinal.'th'; } } ?>

« previous php.notes (#211669) next »