请教一下高手,上面的数组格式,如何才能变成下面的格式,按time值排序,并添加一个date字段?$data = array(
array('title'=>'aaa','content'=>'内容1','time'=>1111111111),
array('title'=>'bbb','content'=>'内容2','time'=>1111111111),
array('title'=>'ccc','content'=>'内容3','time'=>2222222222),
array('title'=>'ddd','content'=>'内容4','time'=>2222222222),
array('title'=>'eee','content'=>'内容5','time'=>3333333333),
array('title'=>'fff','content'=>'内容6','time'=>3333333333)
);$data = array(
0 => array(
'time' => 1111111111,
'date' => 1111111111,
'repay_data' = array(
0 => array(
'title'=>'aaa',
'content'=>'内容1'
),
1 => array(
'title'=>'bbb',
'content'=>'内容2'
)
),
),
1 => array(
'time' => 2222222222,
'date' => 2222222222,
'repay_data' = array(
0 => array(
'title'=>'ccc',
'content'=>'内容3'
),
1 => array(
'title'=>'ddd',
'content'=>'内容4'
)
),
),
2 => array(
'time' => 3333333333,
'date' => 3333333333,
'repay_data' = array(
0 => array(
'title'=>'eee',
'content'=>'内容5'
),
1 => array(
'title'=>'fff',
'content'=>'内容6'
)
),
),
);
array('title'=>'aaa','content'=>'内容1','time'=>1111111111),
array('title'=>'bbb','content'=>'内容2','time'=>1111111111),
array('title'=>'ccc','content'=>'内容3','time'=>2222222222),
array('title'=>'ddd','content'=>'内容4','time'=>2222222222),
array('title'=>'eee','content'=>'内容5','time'=>3333333333),
array('title'=>'fff','content'=>'内容6','time'=>3333333333)
);$data = array(
0 => array(
'time' => 1111111111,
'date' => 1111111111,
'repay_data' = array(
0 => array(
'title'=>'aaa',
'content'=>'内容1'
),
1 => array(
'title'=>'bbb',
'content'=>'内容2'
)
),
),
1 => array(
'time' => 2222222222,
'date' => 2222222222,
'repay_data' = array(
0 => array(
'title'=>'ccc',
'content'=>'内容3'
),
1 => array(
'title'=>'ddd',
'content'=>'内容4'
)
),
),
2 => array(
'time' => 3333333333,
'date' => 3333333333,
'repay_data' = array(
0 => array(
'title'=>'eee',
'content'=>'内容5'
),
1 => array(
'title'=>'fff',
'content'=>'内容6'
)
),
),
);
解决方案 »
- php表单 接收参数
- 在求一个正则
- 這個問題好難整!分不多,但是有點尖銳!
- 新手请教有关Session的问题!
- 关于select ... into outfile的问题,请大家看一下。
- $R=($color>>16) & 0xff; 这句怎么解释?
- ftp_connect的问题:主机地址使用ip可以连接,用域名就连不了?!!!
- php访问页面出错:
- 如何在php中能组织出'{"result":[{"id":"1","name":"j"}]}'这种格式的json啊
- webservice有两个同名的方法,php要怎么调用(请不吝赐教)
- 关于php读取读卡器数据的问题
- SQLserver2005连接PHP是提示错误
array('title'=>'aaa','content'=>'内容1','time'=>1111111111),
array('title'=>'bbb','content'=>'内容2','time'=>1111111111),
array('title'=>'ccc','content'=>'内容3','time'=>2222222222),
array('title'=>'ddd','content'=>'内容4','time'=>2222222222),
array('title'=>'eee','content'=>'内容5','time'=>3333333333),
array('title'=>'fff','content'=>'内容6','time'=>3333333333)
);$res = array();
foreach($data as $item) {
$k = "$item[time]";
if(! isset($res[$k]))
$res[$k] = array(
'time' => $item['time'],
'date' => $item['time'],
);
unset($item[$k]);
$res[$k]['repay_data'][] = $item;
}
$data = array_values($res);
var_export($data);array (
0 =>
array (
'time' => 1111111111,
'date' => 1111111111,
'repay_data' =>
array (
0 =>
array (
'title' => 'aaa',
'content' => '内容1',
'time' => 1111111111,
),
1 =>
array (
'title' => 'bbb',
'content' => '内容2',
'time' => 1111111111,
),
),
),
1 =>
array (
'time' => 2222222222,
'date' => 2222222222,
'repay_data' =>
array (
0 =>
array (
'title' => 'ccc',
'content' => '内容3',
'time' => 2222222222,
),
1 =>
array (
'title' => 'ddd',
'content' => '内容4',
'time' => 2222222222,
),
),
),
2 =>
array (
'time' => 3333333333,
'date' => 3333333333,
'repay_data' =>
array (
0 =>
array (
'title' => 'eee',
'content' => '内容5',
'time' => 3333333333,
),
1 =>
array (
'title' => 'fff',
'content' => '内容6',
'time' => 3333333333,
),
),
),
)