php - Manipulate JSON


I am developing a codeigniter application. I need the returned json data in this format.

        options: [

However, when returning the data, I only have it in this format


Where am I doing it wrong ? The code I am using to generate the json data is

        $users = $this->user_m->get_all();  
        $user_arr = [];
        foreach ($users as $user) {
            $user_arr[$i] = new stdClass();
            $user_arr[$i]->id = $user->id;
            $user_arr[$i]->text = $user->username;
       //add the header here
        header('Content-Type: application/json');
        echo json_encode( $user_arr );




echo json_encode( $user_arr );


echo json_encode( array('options' => $user_arr) );

People are also looking for solutions to the problem: php - grant permission to a new role in Laravel 5


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.