Std class object to array Std class object to array codeigniter codeigniter

Std class object to array


try this :

$array = json_decode(json_encode($objArray), true);

This will work for recursive array also.


What does your model look like where this data is being generated? If you query your database to retrieve arrays you won't have to worry about converting the data.

In codeigniter you can use row_array() instead of row() or result_array() instead of result()

For example change this:

$query = $this->db->get('mytable');$query->get->row();return $query;

Into this:

$query = $this->db->get('mytable');$query->get->row_array();return $query;

In this example I'm using row()/row_array(), but the same applies for result()/result_array()


Try the following :

$array = (array) $object;

Or

$array = get_object_vars($object);