Php – Zend_Db_Table – Associative Array Instead Of Object

MySQLPHPzend-framework

The following line:

$select = $table->select();
$select->where('approved = 1');
$result = $table->fetchRow($select);

Returns an object. What I would like is to get an associative array instead.

I know that Zend_Db has fetchAssoc() method for that but is something similar also in the Zend_Db_Table (I tried fetchAssoc() but it doesn't work, I haven't found anything in the documentation)?

Best Answer

$result = $table->fetchRow($select)->toArray();

Both Zend_Db_Table_Row and Zend_Db_Table_Rowset have a toArray() method. A Row is returned as an associative array, and a Rowset is returned as a simple (ordinal) array of associative arrays.