二维数组中,
$arr = array (
'0' => array ( 'userId' => 1,'thisUrl' => 'a.php', 'dateTime' => '2010-11-17 14:48:30' ),
'1' => array ( 'userId' => 2,'thisUrl' => 'b.php', 'dateTime' => '2010-11-17 14:42:57' ),
'5' => array ( 'userId' => 6,'thisUrl' => 'a.php', 'dateTime' => '2010-11-18 15:02:25')
);
如果不用循环的思路,如何得到 thisUrl为a.php的记录,thanks
$arr = array (
'0' => array ( 'userId' => 1,'thisUrl' => 'a.php', 'dateTime' => '2010-11-17 14:48:30' ),
'1' => array ( 'userId' => 2,'thisUrl' => 'b.php', 'dateTime' => '2010-11-17 14:42:57' ),
'5' => array ( 'userId' => 6,'thisUrl' => 'a.php', 'dateTime' => '2010-11-18 15:02:25')
);
如果不用循环的思路,如何得到 thisUrl为a.php的记录,thanks
'0' => array ( 'userId' => 1,'thisUrl' => 'a.php', 'dateTime' => '2010-11-17 14:48:30' ),
'1' => array ( 'userId' => 2,'thisUrl' => 'b.php', 'dateTime' => '2010-11-17 14:42:57' ),
'5' => array ( 'userId' => 6,'thisUrl' => 'a.php', 'dateTime' => '2010-11-18 15:02:25')
);$key = 'thisUrl';
$value = 'a.php';
$t = array_filter($arr, create_function('$s', "return \$s['$key']=='$value';"));print_r($t);Array
(
[0] => Array
(
[userId] => 1
[thisUrl] => a.php
[dateTime] => 2010-11-17 14:48:30
) [5] => Array
(
[userId] => 6
[thisUrl] => a.php
[dateTime] => 2010-11-18 15:02:25
))
我还提供一个方法,用array_walk
$arr = array (
'0' => array ( 'userId' => 1,'thisUrl' => 'a.php', 'dateTime' => '2010-11-17 14:48:30' ),
'1' => array ( 'userId' => 2,'thisUrl' => 'b.php', 'dateTime' => '2010-11-17 14:42:57' ),
'5' => array ( 'userId' => 6,'thisUrl' => 'a.php', 'dateTime' => '2010-11-18 15:02:25')
);
如果不用循环的思路,如何得到 thisUrl为a.php的记录,有没有更高的效率的方法呢,thanks