On each iteration you should add $longueur to an array and then order the array.

Something like this:



//Outside the loop
$items = array(); //Or $items = []; if you are using PHP 5.4 or...