How to return multidimensional array in codeigniter?

Member

by rollin , in category: PHP Frameworks , a year ago

How to return multidimensional array in codeigniter?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by kadin , a year ago

@rollin 

In CodeIgniter, you can return a multidimensional array by simply creating the array with nested arrays within it and returning it in your controller function. Here's an example:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
public function get_data() {
    $data = array(
        array(
            'name' => 'John Doe',
            'age' => 30
        ),
        array(
            'name' => 'Jane Smith',
            'age' => 25
        ),
        array(
            'name' => 'Bob Johnson',
            'age' => 35
        )
    );

    return $data;
}


You can then access this array in your view or any other part of your application. Just call the get_data() function in your controller and it will return the multidimensional array.

Related Threads:

How to return partial array match in inner array of mongodb?
How to return an array in config file in laravel?
How to return a numpy array as an image using fastapi?
How to get/return last inserted id in codeigniter?
How to convert array into string in Codeigniter?
How to convert array to string in codeigniter?