Sort numbers on a Sept?

Asked

Viewed 46 times

3

I have a table where users select multiple numbers and are recorded in a $_SESSION, I just need these numbers to appear in ascending order:

Example of $_SESSION gravada = 22-20-38-54-52-42-34-18-70-75

I need you to show up like this = 18-20-22-34-38-42-52-54-70-75

1 answer

3


Do the following, turn this string into an array, then sort the array the way you want, and finally convert the array into a string separated by the character you want.

$_SESSION['numbers'] = '22-20-38-54-52-42-34-18-70-75';
$array_numbers = explode( '-', $_SESSION['numbers'] ); // Quebra a string em um array

sort( $array_numbers ); // Ordena o array em ordem crescente

$numbers = implode( '-', $array_numbers ); // Quebra do array em string, separando por "-"

print_r( $numbers ); // Vai imprimir o seguinte resultado: 18-20-22-34-38-42-52-54-70-75

Browser other questions tagged

You are not signed in. Login or sign up in order to post.