Home >Backend Development >PHP Tutorial >Fetch records from a two-dimensional array based on conditions

Fetch records from a two-dimensional array based on conditions

WBOY
WBOYOriginal
2016-07-25 09:09:461076browse
  1. There is an array $point_history (as shown below), take out the array row with user_id = 3.
  2. The code is as follows:
  3. //Your array
  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 is a new array used to receive user_id=3.
  12. $new[] = $point_history[$row];
  13. }
  14. }
  15. //Output the new array.
  16. for($row = 0;$row print_r($new[$row]);
  17. echo "
    ";
  18. }
Copy Code


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn