如何使用ZF2在数组中获取结果


How to fetch results in an array with ZF2

我正试图使用Tablegateway从带有ZF2的DB中获得一些不同的值。

    $select = $this->sql->select($tableGateway->getTable());
    $select->columns(array('city'));
    $select->quantifier('DISTINCT');
    $stm = $this->sql->prepareStatementForSqlObject($select);
    $res = $stm->execute();
    return $res;

这将返回一个Iterate对象,我希望将所有城市都放在一个数组中。我该怎么做?

// whatever $select
$stm = $this->sql->prepareStatementForSqlObject($select);
$res = $stm->execute();
$resultSet = new 'Zend'Db'ResultSet'ResultSet;
$resultSet->initialize($res);
foreach ($resultSet->toArray() as $row) {
    // ...
}