我带来了db的json_encode数据。
foreach ($rslt as $val){
$data[] = $val;
}
echo json_encode($data);
输出为[{"column name":"dbData1"},{"column name":"dbData2"}]
我可以将其替换为自定义名称而不是列名吗?
预期产出:
[{"rec":"dbData1"},{"rec":"dbData2"}]
答案 0 :(得分:2)
这样的事情:
foreach ($rslt as $val){
$data[] = array('rec'=>$val['column name']);
}
echo json_encode($data);
答案 1 :(得分:0)
<?php
$arr = array('rec' => $val["col_name"], 'rec' => $val["col_name2"]);
echo json_encode($arr);
?>