Search code examples
phparraysapicodeigniterobject

array to object codeigniter [REST API]


so i have an ouput data look like this enter image description here

and this is my code

$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);

the problem is i want to return about [{"0":"about us"}] not only array


Solution

  • Make $var2 as an object, not an array

    $var2= new stdClass();
    
    
    $var2->0 = $voucher......