我已将数据库中的记录存储在数组中。 现在我想根据价格指数对数组进行排序,然后根据打印结果。
任何人都能帮助我吗?
我试过的代码..
<?php
include('db.php');
$query = mysql_query("SELECT * FROM user");
$array = array();
while($row = mysql_fetch_assoc($query))
{
$array[] = $row;
$price[]=$row['price'];
}
echo "<pre>";
print_r($array);
输出..
Array
(
[0] => Array
(
[id] => 1
[name] => abc
[email] => abc@gmail.com
[contact] => 27488887
[price] => 12AED
)
[1] => Array
(
[id] => 2
[name] => siddharth
[email] => dgsfgsjkf@gmail.cm
[contact] => 7878787
[price] => 10AED
)
[2] => Array
(
[id] => 3
[name] => abc
[email] => def@gmail.com
[contact] => 4554545
[price] => 2AED
)
[3] => Array
(
[id] => 4
[name] => xyz
[email] => test@gmail.com
[contact] => 878778
[price] => 1AED
)
[4] => Array
(
[id] => 5
[name] => dandas
[email] => sdskagdsa
[contact] => 24221
[price] => 200AED
)
[5] => Array
(
[id] => 6
[name] => ass
[email] => asas
[contact] => 78787
[price] => 3AED
)
)
现在我想按价格对获得的数组进行排序,然后显示记录..