axech
axech

Reputation: 31

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

Upvotes: 0

Views: 1145

Answers (3)

Sachin
Sachin

Reputation: 797

we can force that json_encode uses an object

json_encode($data, JSON_FORCE_OBJECT)

Upvotes: 0

Heru Prasetyo Utomo
Heru Prasetyo Utomo

Reputation: 129

Make $var2 as an object, not an array

$var2= new stdClass();


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

Upvotes: 0

Penyihir 35
Penyihir 35

Reputation: 1

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

Upvotes: 0

Related Questions