$test = array('hola'=>'mundo','salami'=>'frito');
$data = array(
'gift_promoted' => '',
'questions' => array(
0 => array(
'extra' => array()
)
),
'quiz' => array(
'extra' => array(),
$test
)
);
print json_encode($data);
实际结果:
{"gift_promoted":"","questions":[{"extra":[]}],"quiz":{"extra":[],"0":{"hola":"mundo","salami":"frito"}}}
我需要这个:
{"gift_promoted":"","questions":[{"extra":[]}],"quiz":{"extra":[],"hola":"mundo","salami":"frito"}}
答案 0 :(得分:0)
$test = array('hola'=>'mundo','salami'=>'frito'); $data = array(
'gift_promoted' => '',
'questions' => array(
0 => array(
'extra' => array()
)
),
'quiz' => array(
'extra' => array(),
//$test --> remove this.
) );
foreach($test as $key => $value) { $data['quiz'][$key]=$value; }
print json_encode($data);