php - Display records in ascending order when records are like 12.108.90 -
how display records in ascending order using php/mysql when records this:
12.108.90, 7.60.109.3, 56.23.45.78.9, 1.7.9.08 ?
these records multiple frequency numbers, , want display them in ascending order, i'm not getting correct format. current query looks this:
select * revision order revid desc
the revid records similar to: 12.8.90
, 7.889.56.90
, 14.78.0
, , 16.67.87.12
. how can correct query sort records in ascending order?
try using usort
.
eg:
$array = array( '12.108.90', '7.60.109.3', '56.23.45.78.9', '1.7.9.08', ); usort($array, function($a, $b) { $a = explode('.', $a); $b = explode('.', $b); foreach($a $key => $valuea) { if(!isset($b[$key])) { return 1; } $valueb = (int)$b[$key]; $valuea = (int)$valuea; if($valuea === $valueb) { continue; } return $valuea - $valueb; } return -1; }); var_dump($array);
Comments
Post a Comment