[
string(1) => '1st, 2nd, 535',
string(2) => '2nd, 2nd, 13',
string(3) => '3rd, 2nd, 442',
]
$strings = [
'1st, 2nd, 535',
'2nd, 2nd, 13',
'3rd, 2nd, 442',
];
function findString($number, array $strings, $criterionStart=1) {
$found = null;
$criterionEnd = $criterionStart;
foreach ($strings as $string) {
list(2=>$criterionIncrement) = explode(', ', $string);
$criterionEnd += $criterionIncrement;
if ($number>=$criterionStart && $number<$criterionEnd) {
$found = $string;
break;
}
$criterionStart = $criterionEnd;
}
return $found;
}
findString(rand(1,990), $strings);