Blogger Information
Blog 8
fans 0
comment 0
visits 14523
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
php二维数组根据某个字段排序的排序(商品按销量或其他字段排序)
熟悉的新风景
Original
726 people have browsed it

在这里插入图片描述

  1. // 连接数据库
  2. require './includes/connect.class.php';
  3. $conn = Connect::getInstance();
  4. // 获取数据
  5. $res = $conn->fetchAll("SELECT * FROM `b_sale` UNION ALL SELECT * FROM `b_lend` ");
  6. if (isset($_GET['action']) && $_GET['action'] == 'sale') {
  7. // 按销量排序
  8. array_multisort(array_column($res, 'num'), SORT_ASC, $res);
  9. } elseif (isset($_GET['action']) && $_GET['action'] == 'price') {
  10. // 按价格排序
  11. array_multisort(array_column($res, 'price'), SORT_ASC, $res);
  12. }

在这里插入图片描述

Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments