小さな問題が1つあり、移動できません。PHP配列でJSONを作成するには?
$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);
今JSON出力は次のとおりです:
[{"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"}}]
間違っている
私はこのPHPコードを書きました。私は(値を気にしない)、この結果を達成する必要があります。{
"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...
私が間違っているのものを私に示し、どのように私はこれを完了することができますしてください?
アレイを作成してエンコードすると、目的の出力にエンコードされたオブジェクトが表示されます。 – arkascha
私はあなたの代わりにこれが必要なもの: '$ d ['rs'。$ rs] ['c'。$ c] = $ randomRs;' – AbraCadaver
これは明らかです:D – dehood