Input validation above loop works just fine, but not working in loop. Input should not allow: string and negative numbers. Any workaround to do this or just using inside loop is not a go? Yes, I know the maximum entered number can be checked in other ways, but I'm interested in this particular case with "for loop".
$amount = readline("Enter amount of inputs: ");
if (!is_numeric($amount) || !(0 < $amount)){
echo "Invalid input";
exit;
}
$numbers = [];
for ($i = 1; $i <= $amount; $i++){
$numbers[] = readline("Input number {$i}: ");
if (!is_numeric($amount) || !(0 < $amount)){
echo "Invalid input";
exit;
}
}
$largestNumbers = max($numbers);
$numbersList = implode(",", $numbers);
echo "The largest number of $numbersList is $largestNumbers";