Filling an array in PHP Zend Framework and fetching it in the View
<p>I'm trying to fill an array in my PHP ZF2 application controller and pass it onto the view by doing the following: </p>

<pre><code>$brandIds = $this-&gt;getConfig()['brandIds'];
        $array = array();
        $size = count($brandIds);
        for ($i = 0; $i &lt; $size; $i++)
        {
            $brand = $this-&gt;getBrandModel()-&gt;getBrandById($brandIds[$i]);
            $array = array_fill($i,$size, $brand);
        }
        $signInSession = $this-&gt;signInUser-&gt;user;
        if(empty($signInSession))
        {
            $this-&gt;redirect()-&gt;toUrl('/index/landing');
        }
        $viewModel = new ViewModel();
        $viewModel-&gt;setVariable("b",$array);
        return $viewModel;
</code></pre>

<p>Please note that: </p>

<pre><code>$this-&gt;getConfig()['brandIds']
</code></pre>

<p>is an static array which I've predefined in the config file like following: </p>

<pre><code>  "brandIds" =&gt; array(
        "AUTO" =&gt; 16,
        "FINANCE" =&gt; 18,
        "EVENTS" =&gt; 19,
        "HEALTH" =&gt; 21,
        "GADGETS" =&gt; 25
    ),
</code></pre>

<p>And in the view I'm doing the following: </p>

<pre><code>  &lt;?php foreach ($brands as $bId){ ?&gt;
                &lt;h1&gt; &lt;?=$bId?&gt; &lt;/h1&gt;
               &lt;?php }?&gt;
</code></pre>

<p>But when I open up the view in my browser, nothing appears. My question here is, or more of a problem is that I don't understand why nothing shows up on my view. Also, how can I access each element of this array which is fetched from the DB. Like if the table in the DB has column called "id", I'd like to access it by following:</p>

<pre><code>&lt;?=$bId['id']?&gt;
</code></pre>

<p>And write it out on my view (this is just an example, I wouldn't actually print ID from DB lol)...</p>

<p>Can someone help me out with this guys? </p>

<p>Thanks heaps!!</p>