如何创建多维数组?目前这个查询返回给我这个:
Array
(
[id] => 1
[name] => Samsung galaxy S4
[homepage] => 1
)
但我希望我返回这样的数据:
Array
(
[0] => Array
(
[id] => 1
[name] => Samsung galaxy S4
[homepage] => 1
)
[1] => Array
(
[id] => 3
[name] => Iphone 5
[homepage] => 1
)
[2] => Array
(
[id] => 3
[name] => Samsung galaxy S3
[homepage] => 1
)
)
模型:
<?php
namespace Application\Model;
use Zend\Db\Adapter\Adapter;
use Zend\Db\Sql\Sql;
class News
{
const TABLE = 'news';
public function __construct(Adapter $adapter)
{
$this->adapter = $adapter;
$this->sql = new Sql($adapter);
}
public function getNews()
{
$select = $this->sql->select();
$select->from(self::TABLE)
->where(array('homepage' => 1));
$statement = $this->sql->prepareStatementForSqlObject($select);
return $statement->execute()->current();
}
}
问题不在于查询,而是将其全部转化为多维数组。如何从数据库中创建一个数组。