您好,欢迎访问一九零五行业门户网

php数组遍历后重新组装,请教方法

如图代码,组装成下面这种格式,有没有什么办法,数组内长度不定
$_post['huodong']=array( 'shenbing', 'duobao', 'ceshi');$_post['sttime']=array( '2016-11-07 00:00:00', '2016-11-08 00:00:00', '2016-11-09 00:00:00');$_post['edtime']=array( '2016-11-10 00:00:00', '2016-11-11 00:00:00', '2016-11-12 00:00:00');$_post['sourcelmt']=array( array( 'xiaomi_uku_and', 'uc_uku_and', 'qq_uku_and' ), array( 'xiaomi_uku_and', 'qq_uku_and' ), array( 'uc_uku_and', ));

现在想组装成这种格式的:
array( 'shenbing'=>array( 'sttime'=>'2016-11-07 00:00:00', 'edtime'=>'2016-11-10 00:00:00', sourcelmt=array( 'xiaomi_uku_and', 'uc_uku_and', 'qq_uku_and' ), ), 'duobao'=>array( 'sttime'=>'2016-11-08 00:00:00', 'edtime'=>'2016-11-11 00:00:00', sourcelmt=array( 'xiaomi_uku_and', 'qq_uku_and' ), ), 'ceshi'=>array( 'sttime'=>'2016-11-09 00:00:00', 'edtime'=>'2016-11-12 00:00:00', sourcelmt=array( uc_uku_and ), ),);

请问有什么好的办法?感谢~
回复内容: 如图代码,组装成下面这种格式,有没有什么办法,数组内长度不定
$_post['huodong']=array( 'shenbing', 'duobao', 'ceshi');$_post['sttime']=array( '2016-11-07 00:00:00', '2016-11-08 00:00:00', '2016-11-09 00:00:00');$_post['edtime']=array( '2016-11-10 00:00:00', '2016-11-11 00:00:00', '2016-11-12 00:00:00');$_post['sourcelmt']=array( array( 'xiaomi_uku_and', 'uc_uku_and', 'qq_uku_and' ), array( 'xiaomi_uku_and', 'qq_uku_and' ), array( 'uc_uku_and', ));

现在想组装成这种格式的:
array( 'shenbing'=>array( 'sttime'=>'2016-11-07 00:00:00', 'edtime'=>'2016-11-10 00:00:00', sourcelmt=array( 'xiaomi_uku_and', 'uc_uku_and', 'qq_uku_and' ), ), 'duobao'=>array( 'sttime'=>'2016-11-08 00:00:00', 'edtime'=>'2016-11-11 00:00:00', sourcelmt=array( 'xiaomi_uku_and', 'qq_uku_and' ), ), 'ceshi'=>array( 'sttime'=>'2016-11-09 00:00:00', 'edtime'=>'2016-11-12 00:00:00', sourcelmt=array( uc_uku_and ), ),);

请问有什么好的办法?感谢~
$result = array();foreach($_post['huodong'] as $first_key => $id) { // 此处的 '' 和 array() 是作为默认值 foreach(array('sttime'=>'','edtime'=>'','sourcelmt'=>array()) as $second_key => $val) { $result[$id][$second_key] = isset($_post[$second_key][$first_key]) ? $_post[$second_key][$first_key] : $val; }}print_r($result);
根据 下标取不同 数组对应下标的值就行了啊
$result = array();
for($i=0;$i$result[$_post['huodong'][$i]]=array( 'sttime'=>$_post['sttime'][$i], 'edtime'=>$_post['edtime'][$i], 'sourcelmt'=>$_post['sourcelmt'][$i], );
}
print_r($result);
其它类似信息

推荐信息