codeigniter 对象代码触发器的数组[REST API]

wlwcrazw  于 2022-12-07  发布在  其他
关注(0)|答案(3)|浏览(132)

因此,输出数据如下所示:x1c 0d1x
这是我的代码

$var1[] = array('0' => $about_us,
                '1' => $privacy,
                '2' => $term_condition,
                '3' => $copyright,
                '4' => $faq);
                    $var2[] = array('0' => $voucher_redemption,
                                 '1' => $contact_us);
                    $var3[] = array('0' => $about_point,
                                 '1' => $earn_point,
                                 '2' => $redeem_voucher);

                    $array["ABOUT"]=$var1;
                    $array["SUPPORT"]=$var2;
                    $array["POINT"]=$var3;
                    $final[]=$array;

                    $data["STATUS"] = "SUCCESS";
                    $data["MASSAGE"] = "LIST FOOTER TITLE";
                    $data["DATA"] = $final;
                   echo json_encode($data);

问题是我想返回about [{“0”:“about us”}],而不仅仅是数组

xlpyo6sf

xlpyo6sf1#

使$var2成为对象,而不是数组

$var2= new stdClass();

$var2->0 = $voucher......
ct3nt3jp

ct3nt3jp2#

$result = array();

foreach($todo->result() as $hasil) {

    $result[] = array(   
        'id_todo'         => $hasil->id_todo,                     
        'tanggal_input'   => $hasil->tanggal_input,
        'mapel'           => $hasil->mapel,
        'catatan'         => $hasil->catatan                        
    );
}
wtzytmuj

wtzytmuj3#

我们可以强制json_encode使用一个

json_encode($data, JSON_FORCE_OBJECT)

相关问题