atman atta Sun Jun 12 14:44:52 -0400 2011

Subject: How to get result set as an array?


I looked around but was unable to find how I can convert a result from Item::find('all') directly into an array representing in a pure PHP array hash?

Thank you

Daniel Lowrey Sun Jun 12 15:39:36 -0400 2011

The documentation is a bit out-of-date and doesn't reflect this, but version 1.0 model objects offer a to_array() serializer method.

It's the same as the to_json() and to_xml() methods documented in the Serialization section of the docs:

So, for example:

$results = MyModel::find('all', array('limit'=>5));
foreach($results as $r) { print_r($r->to_array()); }