2 回答

TA貢獻1811條經(jīng)驗 獲得超6個贊
$a=[];
$b=new stdClass();
$k1="12:00";
$k2="12:50";
$k3="13:10";
$b->$k1=1;
$b->$k2=2;
$b->$k3=3;
$a[]=$b;
echo json_encode($a);
結(jié)果
[{
"12:00": 1,
"12:50": 2,
"13:10": 3
}]
你想要這樣的結(jié)果嗎?
完整版本:
$flat=new stdClass();
foreach($tempreserve as $obj) {
$a=json_decode(json_encode($obj),true);
$k=array_keys($a)[0];
$v=$a[$k];
$flat->$k=$v;
}
echo (json_encode($flat));

TA貢獻1824條經(jīng)驗 獲得超8個贊
您可以使用foreachand json_encode,$arr是數(shù)組
$res = [];
foreach($arr as $key => $value){
foreach($value as $innerkey => $innerValue){
$res[$innerkey] = $innerValue;
}
}
echo json_encode($res);
- 2 回答
- 0 關(guān)注
- 169 瀏覽
添加回答
舉報