그림과 같이 코드가 아래와 같은 형식으로 되어 있는데, 배열의 길이가 가변적인 방법이 있나요?
<code>$_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', ) );</code>
<code>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 ), ), );</code>
답글 내용:
이제 다음 형식으로 정리하고 싶습니다.
<code>$_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', ) );</code>
무슨 방법이 좋을까요? 감사합니다~
<code>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 ), ), );</code>
<code>$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);</code>
$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);