PhpRiot
Become Zend Certified

Prepare for the ZCE exam using our quizzes (web or iPad/iPhone). More info...


When you're ready get 7.5% off your exam voucher using voucher CJQNOV23 at the Zend Store

Retrieving a Rowset as an Array

You can access all the data in the Rowset as an array using the toArray() method of the Rowset object. This returns an array containing one entry per Row. Each entry is an associative array having keys that correspond to column names and elements that correspond to the respective column values.

Example 324. Using toArray()

<?php
$bugs   
= new Bugs();
$rowset $bugs->fetchAll();

$rowsetArray $rowset->toArray();

$rowCount 1;
foreach (
$rowsetArray as $rowArray) {
    echo 
"row #$rowCount:\n";
    foreach (
$rowArray as $column => $value) {
        echo 
"\t$column => $value\n";
    }
    ++
$rowCount;
    echo 
"\n";
}

The array returned from toArray() is not updateable. That is, you can modify values in the array as you can with any array, but changes to the array data are not propagated to the database.

Zend Framework