2016-11-11 2 views
-1
$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); 

Tatsächliches Ergebnis:So entfernen Sie diese "0": {aus einem Array

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

annotated screenshot

Ich brauche dies:

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

Sie können 'unset' verwenden. –

+0

Das Duplikat ist falsch. In dieser Frage geht es darum, [0 => $ v] in $ v zu ändern, wodurch ein Element nicht genau gelöscht wird. – SOFe

+0

Genau das Problem ist nicht dupliziert –

Antwort

0

ein wenig schmutzig:

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