Jump to content

Odering Numbers


Recommended Posts

<?php
$numbers = array(1, 30, 29, 3, 9, 12, 30, 1, 30);

sort($numbers, SORT_NUMERIC);
print_r($numbers);
/*
Array
(
    [0] => 1
    [1] => 1
    [2] => 3
    [3] => 9
    [4] => 12
    [5] => 29
    [6] => 30
    [7] => 30
    [8] => 30
)
*/

$numCount = array_count_values($numbers);
print_r($numCount);
/*
Array
(
    [1] => 2
    [3] => 1
    [9] => 1
    [12] => 1
    [29] => 1
    [30] => 3
)
*/
?>

Link to comment
https://forums.phpfreaks.com/topic/49850-odering-numbers/#findComment-244555
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.