|
|
|
อยาก Sort value ใน Array 2 ครั้งอ่ะครับ PHP ครับ มีตัวอย่างด้านใน |
|
|
|
|
|
|
|
ลองดูครัยไม่รู้ได้มั้ย
array-multisort
array-multisort
|
|
|
|
|
Date :
2018-01-17 10:38:26 |
By :
mangkunzo |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ตรวจสอบ ทั้งสอง field สิครับ
Code (PHP)
<?php
$data[0]['GUEST'] = 1;
$data[0]['BAMOUNT'] = 500;
$data[1]['GUEST'] = 2;
$data[1]['BAMOUNT'] = 500;
$data[2]['GUEST'] = 1;
$data[2]['BAMOUNT'] = 100;
$data[3]['GUEST'] = 2;
$data[3]['BAMOUNT'] = 100;
$data[4]['GUEST'] = 3;
$data[4]['BAMOUNT'] = 1500;
$data[5]['GUEST'] = 1;
$data[5]['BAMOUNT'] = 1000;
usort($data, 'compare');
function compare($x, $y)
{
if($x===$y) return 0;
if ($x['GUEST'] < $y['GUEST']) { return -1;}
else if ($x['GUEST'] == $y['GUEST']) {
if ($x['BAMOUNT'] < $y['BAMOUNT']) { return -1;}
}
return 1;
}
echo '<pre>'.print_r($data, true).'</pre>';
|
ประวัติการแก้ไข 2018-01-17 12:09:57
|
|
|
|
Date :
2018-01-17 12:02:30 |
By :
Chaidhanan |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 01
|