PHP Build a Basic PHP Website (2018) Listing and Sorting Inventory Items Working with Functions

Why output is in a reverse mode?

<?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;

?>

Why It outputs 321 instead of 123?? I Don't get It..

1 Answer

Because of the way you concatenate $number with $output. Each time through the loop you put $number in front of $output, not behind:

$output = $number . $output;

Yeah... I realized it 10seconds ago, but much thanks to you, mate! :)