- implode: documentation ( source)
- range: documentation ( source)
- array_walk: documentation ( source)
- printf: documentation ( source)
<?php
$ordinalFormatter = new NumberFormatter('en', NumberFormatter::ORDINAL);
$numbers = range(1, 30);
$ordinals = [];
array_walk($numbers, function ($number) use ($ordinalFormatter, $ordinals) {
$ordinals[] = $ordinalFormatter->format($number);
});
printf("Ordinals: %s\n", implode(', ', $ordinals));