Ich habe ein kleines Problem und kann nicht weitermachen.Wie erstelle ich JSON mit PHP-Array?
Ich schrieb diesen PHP-Code:
$d=array();
foreach(range(0, 3) as $rs) {
foreach(range(0, 5) as $c){
//here is working php code to generate '$randomRs' by '$rs' and '$c' vars..
$d[] = array('rs'.$rs => array('c'.$c => $randomRs));
}
}
echo json_encode($d);
Jetzt JSON Ausgabe lautet:
[{"rs0":{"c0":"bl"}},{"rs0":{"c1":"pl"}},{"rs0":{"c2":"bl"}},{"rs0":{"c3":"pl"}},{"rs0":{"c4":"pl"}},{"rs0":{"c5":"wd1"}},{"rs1":{"c0":"lk"}},{"rs1":{"c1":"gr"}},{"rs1":{"c2":"lk"}},{"rs1":{"c3":"gr"}},{"rs1":{"c4":"lk"}},{"rs1":{"c5":"gr"}},{"rs2":{"c0":"u1"}},{"rs2":{"c1":"u1"}},{"rs2":{"c2":"u1"}},{"rs2":{"c3":"wt"}},{"rs2":{"c4":"u1"}},{"rs2":{"c5":"u1"}},{"rs3":{"c0":"u1"}},{"rs3":{"c1":"u1"}},{"rs3":{"c2":"u1"}},{"rs3":{"c3":"u1"}},{"rs3":{"c4":"cl"}},{"rs3":{"c5":"ir"}}]
was falsch ist. Ich brauche dieses Ergebnis zu erreichen (keine Werte beachten):
{
"rs0":{
"c0":"pl",
"c1":"pl",
"c2":"pl",
"c3":"pl",
"c4":"pl"
},
"rs1":{
"c0":"pl",
"c1":"pl",
"c2":"pl",
"c3":"pl",
"c4":"pl"
}
and so on...
Bitte zeigen Sie mir, was ich falsch mache und wie kann ich dieses vollenden?
Sie erstellen und codieren ein Array, die gewünschte Ausgabe zeigt ein codiertes Objekt. – arkascha
ich, was müssen Sie diese stattdessen: '$ d [ 'rs' $ rs.] [ 'C' $ c.] = $ RandomRs;' – AbraCadaver
Es ist jetzt offensichtlich: D – dehood