php数组操作
原数组Array([0]=>Array([kc_id]=>6[signed]=>Array([0]=>Array([id]=>108[time]=>1469232300)...
原数组
Array
(
[0] => Array
(
[kc_id] => 6
[signed] => Array
(
[0] => Array
(
[id] => 108
[time] => 1469232300
)
[1] => Array
(
[id] => 109
[time] =>
)
[2] => Array
(
[id] => 110
[time] =>
)
[3] => Array
(
[id] => 111
[time] =>
)
)
)
[1] => Array
(
[kc_id] => 6
[signed] => Array
(
[0] => Array
(
[id] => 108
[time] => 1469232597
)
[1] => Array
(
[id] => 109
[time] => 1469254964
)
[2] => Array
(
[id] => 110
[time] =>
)
[3] => Array
(
[id] => 111
[time] =>
)
)
)
)
组合成: Array
(
[0] => Array
(
[kc_id] => 6
[108]=>1469232300
[109]=>x
[110]=>x
[111]=>x
)
[1] => Array
(
[kc_id] => 6
[108]=>1469232597
[109]=>1469254964
[110]=>x
[111]=>x
)
)
空的用x填充 展开
Array
(
[0] => Array
(
[kc_id] => 6
[signed] => Array
(
[0] => Array
(
[id] => 108
[time] => 1469232300
)
[1] => Array
(
[id] => 109
[time] =>
)
[2] => Array
(
[id] => 110
[time] =>
)
[3] => Array
(
[id] => 111
[time] =>
)
)
)
[1] => Array
(
[kc_id] => 6
[signed] => Array
(
[0] => Array
(
[id] => 108
[time] => 1469232597
)
[1] => Array
(
[id] => 109
[time] => 1469254964
)
[2] => Array
(
[id] => 110
[time] =>
)
[3] => Array
(
[id] => 111
[time] =>
)
)
)
)
组合成: Array
(
[0] => Array
(
[kc_id] => 6
[108]=>1469232300
[109]=>x
[110]=>x
[111]=>x
)
[1] => Array
(
[kc_id] => 6
[108]=>1469232597
[109]=>1469254964
[110]=>x
[111]=>x
)
)
空的用x填充 展开
展开全部
$array = array(Array('kc_id' => 6,'signed' => Array(Array('id' => 108,'time' => 1469232300),Array('id' => 109,'time' => ''), Array('id' => 110,'time' => ''),Array('id' => 111,'time' => ''))),Array('kc_id' => 6,'signed' => Array(Array('id' => 108,'time' => 1469232300),Array('id' => 109,'time' => ''), Array('id' => 110,'time' => ''),Array('id' => 111,'time' => ''))));
function get_array_by_key($array , $key1 ,$key2)
{
$result = array();
foreach ( $array as $k => $value) {
$result[$value[$key1]] = $value[$key2] ? $value[$key2] : 'x';
}
return $result;
}
$data = array();
foreach($array as $key => $value){
$data[$key] = get_array_by_key($value['signed'],'id','time');
$data[$key]['kc_id'] = $value['kc_id'];
}
print_r($data);
function get_array_by_key($array , $key1 ,$key2)
{
$result = array();
foreach ( $array as $k => $value) {
$result[$value[$key1]] = $value[$key2] ? $value[$key2] : 'x';
}
return $result;
}
$data = array();
foreach($array as $key => $value){
$data[$key] = get_array_by_key($value['signed'],'id','time');
$data[$key]['kc_id'] = $value['kc_id'];
}
print_r($data);
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
foreach( $data as $k => $v){
$newdata[$k]['kc_id'] = $v['kc_id'];
foreach( $v['signed'] as $i => $r){
$newdata[$k][$['id']] = $r['time'] ? $r['time'] : 'x';
}
}
追问
syntax error, unexpected '[', expecting variable (T_VARIABLE) or '$'
追答
foreach( $data as $k => $v){
$newdata[$k]['kc_id'] = $v['kc_id'];
foreach( $v['signed'] as $i => $r){
$newdata[$k][$r['id']] = $r['time'] ? $r['time'] : 'x';
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2016-07-26 · 百度知道合伙人官方认证企业
育知同创教育
1【专注:Python+人工智能|Java大数据|HTML5培训】 2【免费提供名师直播课堂、公开课及视频教程】 3【地址:北京市昌平区三旗百汇物美大卖场2层,微信公众号:yuzhitc】
向TA提问
关注
展开全部
遇到什么问题了?
追问
数组操作
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询