Code, assembled into the following format, is there any way, the length of the array is not fixed {code ...} to assemble the code in this format: {code ...} is there any good solution? Thanks ~ Code, assembled into the following format, is there any way, the length of the array is not fixed
$_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', ));
Now we want to assemble it into this format:
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 ), ),);
Is there any good solution? Thanks ~
Reply content:
Code, assembled into the following format, is there any way, the length of the array is not fixed
$_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', ));
Now we want to assemble it into this format:
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 ), ),);
Is there any good solution? Thanks ~
$ Result = array (); foreach ($ _ POST ['huodong'] as $ first_key => $ id) {// Here ''and array () yes as the default value 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 );
Just use the subscript to retrieve the values corresponding to the lower mark of different arrays.
$ Result = array ();
For ($ I = 0; $ I < p><>
$result[$_POST['huodong'][$i]]=array( 'sttime'=>$_POST['sttime'][$i], 'edtime'=>$_POST['edtime'][$i], 'sourcelmt'=>$_POST['sourcelmt'][$i], );
}
Print_r ($ result );