La Cotizada Ramirez La Cotizada Ramirez - 21 days ago 5
JSON Question

How to remove this "0": {from an array

$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);


Actual result:

{"gift_promoted":"","questions":[{"extra":[]}],"quiz":{"extra":[],"0":{"hola":"mundo","salami":"frito"}}}


annotated screenshot

I need this is:

{"gift_promoted":"","questions":[{"extra":[]}],"quiz":{"extra":[],"hola":"mundo","salami":"frito"}}

Answer

a little dirty:

$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);
Comments