When you have a control structure such as a for loop or an if statement and you don't include a set of brackets after it, only the next line is considered to be inside the control structure.
So when you have
for ($i = 1;$i < $wieviele;$i++)
if ($first < $arg[$i])
$first = $arg[$i];
return $first;
It means
for ($i = 1;$i < $wieviele;$i++){
if ($first < $arg[$i]){
$first = $arg[$i];
}
}
return $first;
That is, it sets $first
equal to $arg[$i]
when appropriate and returns once the loop is finished.
In your code, you have
for ($i = 1;$i < $wieviele;$i++){
if ($first < $arg[$i])
$first = $arg[$i];
return $first;
}
Which is equivalent to
for ($i = 1;$i < $wieviele;$i++){
if ($first < $arg[$i]){
$first = $arg[$i];
}
return $first;
}
So you'll enter the first iteration of the loop, check the condition, and then return $first
. That is, you return after the first iteration, not when the loop is complete.
My advice concerning omitting/including brackets is to always be as explicit as you can, to make the purpose and effect of your code as intuitive as possible.