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

Issue connect string

I THINK THIS CODE HAD RESULT 123 BUT WRONG I DONT KNOW WHY

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

?>

1 Answer

Simon Coates
Simon Coates
28,686 Points

$output = $number . $output; vs $output = $output.$number;

It's adding the new value at the beginning.