二维数组中,
$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

解决方案 »

  1.   

    $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')   
    );$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
            ))
      

  2.   

    楼上的解法让我打开眼界了
    我还提供一个方法,用array_walk
      

  3.   

    呵呵 1楼的还是循环啊 $arr如果是固定的,那么可以使用$arr[0]来访问
      

  4.   

    二维数组中,
    $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