欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

二维数组根据条件取出记录

程序员文章站 2022-05-07 12:54:07
...
  1. 有个数组$point_history(如下),取出 user_id = 3的那一行数组。
  2. 代码如下:
  3. //你的数组
  4. $point_history = array(
  5. array("id"=>1,"user_id"=>1,"points"=>2),
  6. array("id"=>2,"user_id"=>3,"points"=>2),
  7. array("id"=>3,"user_id"=>3,"points"=>2),
  8. array("id"=>4,"user_id"=>3,"points"=>2),
  9. );
  10. for($row = 0;$row if($point_history[$row]["user_id"] == 3){
  11. //$new是个新的数组用于接收user_id=3的。
  12. $new[] = $point_history[$row];
  13. }
  14. }
  15. //输出新的数组。
  16. for($row = 0;$row print_r($new[$row]);
  17. echo "
    ";
  18. }
复制代码