//$mystring_val
$string_val=56149-1853,55847-1588 ;
$newarr= explode(",",$string_val);
print_r ($newarr);
$result = array();
$res = array();
foreach ($newarr as $key=>$value){
$res['multicheque_array_items'][]= explode("-",$value);
}
echo "<br/><br/>====<br/>";
print_r ($res);
我的输出是:
Array
(
[multicheque_array_items] => Array
(
[0] => Array
(
[0] => 56149
[1] => 1853
)
[1] => Array
(
[0] => 55847
[1] => 1588
)
)
)
但我想要这样的输出
Array
(
[multidimensional] => Array
(
[paynum] => Array
(
[payid] => 56149
[itemid] => 1853
)
)
[multidimensional] => Array
(
[paynum] => Array
(
[payid] => 55847
[itemid] => 1588
)
)
)
答案 0 :(得分:0)
$string_val='56149-1853,55847-1588' ;
$newarr= explode(",",$string_val);
foreach ($newarr as $key=>$value){
$temp = explode("-",$value);
for($i=0;$i<count($temp);$i++){
if($i==0)
$res['multidimensional_'.$key]['paynum']['payid'] = $temp[0];
else
$res['multidimensional_'.$key]['paynum']['itemid'] = $temp[1];
}
}
echo "<pre>";
print_r ($res);
它会将输出显示为,
Array
(
[multidimensional_0] => Array
(
[paynum] => Array
(
[payid] => 56149
[itemid] => 1853
)
)
[multidimensional_1] => Array
(
[paynum] => Array
(
[payid] => 55847
[itemid] => 1588
)
)
)
修正了你的代码...... !!
答案 1 :(得分:0)
看看你是否可以使用它: -
$arr=array('multicheque_array_items' => array(
array(56149,1853),array(55847,1588)
)
);
$out=array();
$keys=array('payid','itemid');
foreach($arr['multicheque_array_items'] as $items){
$out['multicheque_array_items'][]=array_combine($keys,$items);
}
echo '<pre>';
print_r($out);
输出: -
Array
(
[multicheque_array_items] => Array
(
[0] => Array
(
[payid] => 56149
[itemid] => 1853
)
[1] => Array
(
[payid] => 55847
[itemid] => 1588
)
)
)