使用多维数组中的重复值对数组进行分组



我有这个数组格式,我从mysql数据库查询。我查询的数据有一些重复,所以我删除了重复的数据。结果查询如下数组格式

[0] => a
[1] => b

[2] => Array
    (
        [ch] => a
        [op] => 1
        [in] => 2012-12-20 09:28:53
    )
[3] => Array
    (
        [ch] => b
        [op] => 2
        [in] => 2012-12-20 19:44:10
    )

[4] => Array
    (
        [ch] => a
        [op] => 1000
        [in] => 2012-12-23 18:21:40
    )
[5] => Array
    (
        [ch] => b
        [op] => 1000
        [in] => 2012-12-23 18:26:16
    )

[6] => Array
    (
        [ch] => a
        [op] => 1000
        [in] => 2012-12-24 12:10:55
    )

如何使用其中一个值作为键来输出这种数组。

[a] => array(
[op] => 1000
[in] => 2012-12-24 12:10:55
      ),
Array
(
[op] => 1000
[in] => 2012-12-23 18:21:40
    )
[b]=> Array
    (
        [op] => 1000
        [in] => 2012-12-23 18:26:16
    )

等。

simply use array_push function,first define a blank array and grt value in it using array_push
eg.
$final_arr=array();
data=mysql_fetch_assoc($query);
array_push($final_arr,$data);

相关内容

  • 没有找到相关文章

最新更新