Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

how can I create a multidimensional array? currently this query returns me this:

Array
(
    [id] => 1
    [name] => Samsung galaxy S4 
    [homepage] => 1
)

but I wish that I returned the data like this:

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
        )
)

Model:

<?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();        
    }
}

The problem is not in the query but in turn it all into multidimensional array. How do I create an array so from the database.

share|improve this question
2  
You return ->current() that selects the FIRST entry of your Multi-Dimensional array, which would be returned by $statement->execute() - cut the ->current() and you got what you want – Sam yesterday

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.