# Can someone explain why this code outputs 321

```<?php

\$numbers = array(1,2,3,4);

\$total = count(\$numbers);

\$sum = 0;

\$output = "";

\$i = 0;

foreach(\$numbers as \$number) {

\$i = \$i + 1;

if (\$i < \$total) {

\$output = \$number . \$output;

}

}

echo \$output;

?>
```

## 5 Answers the loop iterates with number being 1, then 2, then 3, then 4. The value i increases such that when number is four, the string concatenation is bypassed. So the loop is effectively just for when number is 1, 2, 3, add the number to the beginning of a string. So the string is "1", then "21", then "321".

"add the number to the beginning of a string". \$output = \$number . \$output; I get that \$number is one iteration. "\$number . \$output" looks like it would concatenate 1 with 2. 12 then 123. Obviously I'm missing something. I guess my question is what mechanism is causing the numbers to go to the beginning of the string instead of the usual sequence? And thank you for your help

Simon Coates I didn't under when you said add the number to the beginning of a string. So the string is "1", then "21", then "321"" i am totally confused here.

that was fast! Then my next question: is that a usual, common or practical thing to do? Or was it put in the quiz just to make me think?

lol, thank you for that last comment. You made my night! and thank you again for your help :D

Hi victor, yea..when I come to something like that in a quiz I think: 1: did I miss something in the lesson? 2: that doesn't look even remotely familiar. 3: maybe I'm in over my head. At any given time any number of the above may be completely true or false.
Code on, never give up.