龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > web编程 > php编程 >

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

时间:2014-07-22 14:52来源: 作者: 点击:
分享到:
<无详细内容>
有个数组$point_history(如下),取出	user_id = 3的那一行数组。
代码如下:
//你的数组
	$point_history = array(
		array("id"=>1,"user_id"=>1,"points"=>2),
		array("id"=>2,"user_id"=>3,"points"=>2),
		array("id"=>3,"user_id"=>3,"points"=>2),
		array("id"=>4,"user_id"=>3,"points"=>2),
	);
	for($row = 0;$row <sizeof($point_history);$row++){
		if($point_history[$row]["user_id"] == 3){
			//$new是个新的数组用于接收user_id=3的。
			$new[] = $point_history[$row];
		}
	}
	//输出新的数组。
	for($row = 0;$row <sizeof($new);$row++){
		print_r($new[$row]);
		echo "<br />";
	}
精彩图集

赞助商链接