// Created on savesnippets.com ยท https://savesnippets.com/m9LORzsdaHLYAy 'st', 2 => 'nd', 3 => 'rd', default => 'th', }; } foreach ([1, 2, 3, 4, 11, 12, 21, 22, 101, 103] as $n) { echo ordinal($n), ' '; } // 1st 2nd 3rd 4th 11th 12th 21st 22nd 101st 103rd