title: Array within array using foreach loop in codeigniter
body: <p>I am new in codeigniter framework. I am making an array within array and within array using foreach loop for getting record from 3 tables. I have make like this way array</p>
  <pre><code>Array
  (
  [devices] =&gt; Array
      (
          [0] =&gt; Array
              (
                  [id] =&gt; 1
                  [device_name] =&gt; Smartphone
                  [device_image] =&gt; device-images/1d57a675edbb2ff97c5bc35fce27517c.png
                  [device_icon] =&gt; device-images/325af5a3587cdfc8f35ae345a2d432a3.png
                  [all_manufacturers] =&gt; Array
                      (
                          [0] =&gt; Array
                              (
                                  [id] =&gt; 1
                                  [fk_device_id] =&gt; 1
                                  [manufacture] =&gt; Apple
                                  [models] =&gt; Array
                                      (
                                          [0] =&gt; Array
                                              (
                                                  [id] =&gt; 1
                                                  [fk_deviceid] =&gt; 1
                                                  [fk_manufactureid] =&gt; 1
                                                  [model_name] =&gt;  iPhone 11 Pro Max 
                                              )
  
                                          [1] =&gt; Array
                                              (
                                                  [id] =&gt; 2
                                                  [fk_deviceid] =&gt; 1
                                                  [fk_manufactureid] =&gt; 1
                                                  [model_name] =&gt;  iPhone 11 Pro 
                                              )
  
                                          [2] =&gt; Array
                                              (
                                                  [id] =&gt; 3
                                                  [fk_deviceid] =&gt; 1
                                                  [fk_manufactureid] =&gt; 1
                                                  [model_name] =&gt; iPhone 11
                                              )
  
                                      )
  
                              )
  
                          [1] =&gt; Array
                              (
                                  [id] =&gt; 2
                                  [fk_device_id] =&gt; 1
                                  [manufacture] =&gt; Samsung
                                  [models] =&gt; Array
                                      (
                                      )
  
                              )
  
                          [2] =&gt; Array
                              (
                                  [id] =&gt; 3
                                  [fk_device_id] =&gt; 1
                                  [manufacture] =&gt; huawei
                                  [models] =&gt; Array
                                      (
                                      )
  
                              )
  
                          [3] =&gt; Array
                              (
                                  [id] =&gt; 5
                                  [fk_device_id] =&gt; 1
                                  [manufacture] =&gt; Sony
                              )
  
                      )
  
              )
  
          [1] =&gt; Array
              (
                  [id] =&gt; 2
                  [device_name] =&gt; Tablet
                  [device_image] =&gt; device-images/fd9e3f3192547a89c07e30fbcb7e202b.png
                  [device_icon] =&gt; device-images/9f39fb4583174c71e3b7f92ec3e5ed86.png
                  [all_manufacturers] =&gt; Array
                      (
                          [0] =&gt; Array
                              (
                                  [id] =&gt; 6
                                  [fk_device_id] =&gt; 2
                                  [manufacture] =&gt; Apple
                                  [models] =&gt; Array
                                      (
                                          [0] =&gt; Array
                                              (
                                                  [id] =&gt; 4
                                                  [fk_deviceid] =&gt; 2
                                                  [fk_manufactureid] =&gt; 6
                                                  [model_name] =&gt; iPad 3 (2012)
                                              )
  
                                          [1] =&gt; Array
                                              (
                                                  [id] =&gt; 6
                                                  [fk_deviceid] =&gt; 2
                                                  [fk_manufactureid] =&gt; 6
                                                  [model_name] =&gt; iPad 2 (2011)
                                              )
  
                                          [2] =&gt; Array
                                              (
                                                  [id] =&gt; 7
                                                  [fk_deviceid] =&gt; 2
                                                  [fk_manufactureid] =&gt; 6
                                                  [model_name] =&gt; iPad 4 (2012)
                                              )
  
                                      )
  
                              )
  
                          [1] =&gt; Array
                              (
                                  [id] =&gt; 7
                                  [fk_device_id] =&gt; 2
                                  [manufacture] =&gt; Microsoft
                              )
  
                      )
  
              )
  
          [2] =&gt; Array
              (
                  [id] =&gt; 3
                  [device_name] =&gt; Laptop
                  [device_image] =&gt; device-images/60042e62d2fa440d3c467114538a1293.png
                  [device_icon] =&gt; device-images/2044d96ba9274b5b1e3155103fa90506.png
                  [all_manufacturers] =&gt; Array
                      (
                          [0] =&gt; Array
                              (
                                  [id] =&gt; 11
                                  [fk_device_id] =&gt; 3
                                  [manufacture] =&gt; Apple
                              )
  
                      )
  
              )
  
          [3] =&gt; Array
              (
                  [id] =&gt; 4
                  [device_name] =&gt; Watch
                  [device_image] =&gt; device-images/8f10aad91a793372e50a3275db132e4e.png
                  [device_icon] =&gt; device-images/788dc55b9b6e0f805d63a42fd888e1bb.png
                  [all_manufacturers] =&gt; Array
                      (
                          [0] =&gt; Array
                              (
                                  [id] =&gt; 9
                                  [fk_device_id] =&gt; 4
                                  [manufacture] =&gt; Apple
                              )
  
                      )
  
              )
  
          [4] =&gt; Array
              (
                  [id] =&gt; 6
                  [device_name] =&gt; Camera
                  [device_image] =&gt; device-images/88929629884491fd080505b56f1b2b0d.png
                  [device_icon] =&gt; device-images/88fa1d78fe127e757c1cfc90ec925a14.png
              )
  
      )
     )
  </code></pre>
  <p><strong>Issue in view page because showing notice error of Undefined index: all_manufacturers</strong>
  view page code is below</p>
  <pre><code>  &lt;div class=&quot;row&quot;&gt;
      &lt;div class=&quot;col-lg-3 col-md-6&quot;&gt;
          &lt;div class=&quot;sidebar&quot;&gt;
         &lt;?php if($devices) { 
              foreach($devices as $dkey =&gt; $device) { 
                $all_manufacturers = $device[&quot;all_manufacturers&quot;];?&gt;
                  &lt;div class=&quot;dropdown cust-dropdown&quot;&gt;
                   &lt;button class=&quot;btn-dropdown cust-btn-dropdown&quot; type=&quot;button&quot;&gt;&lt;div class=&quot;box-shop-icons&quot;&gt;&lt;img src=&quot;&lt;?= base_url('assets/uploads/'.$device[&quot;device_icon&quot;])?&gt;&quot; &gt;&lt;/div&gt;
                   &lt;?= $device['device_name']?&gt;
                   &lt;/button&gt;
                   &lt;div class=&quot;dropdown-menu-custom&quot;&gt;
                   &lt;div class=&quot;radio-btns cust-height&quot;&gt;
                    &lt;!-- inner radio button --&gt;
                      &lt;?php if ($all_manufacturers) {
                         foreach ($all_manufacturers as $manufacture) { ?&gt;
                           &lt;div class=&quot;dropdown&quot;&gt;
                            &lt;button class=&quot;btn btn-primary dropdown-toggle&quot; type=&quot;button&quot; data-toggle=&quot;dropdown&quot;&gt;&lt;?= $manufacture['manufacture']?&gt;
                            &lt;span class=&quot;caret&quot;&gt;&lt;/span&gt;&lt;/button&gt;
                            &lt;ul class=&quot;dropdown-menu&quot;&gt;
                            &lt;li&gt;&lt;a href=&quot;#&quot;&gt;iPhone 11 pro max&lt;/a&gt;&lt;/li&gt;
                            &lt;li&gt;&lt;a href=&quot;#&quot;&gt;iPhone 11 pro&lt;/a&gt;&lt;/li&gt;
                            &lt;li&gt;&lt;a href=&quot;#&quot;&gt;iPhone 11&lt;/a&gt;&lt;/li&gt;
                            &lt;li&gt;&lt;a href=&quot;#&quot;&gt;iPhone Xs max&lt;/a&gt;&lt;/li&gt;
                            &lt;li&gt;&lt;a href=&quot;#&quot;&gt;iPhone Xs&lt;/a&gt;&lt;/li&gt;
                            &lt;li&gt;&lt;a href=&quot;#&quot;&gt;iPhone X&lt;/a&gt;&lt;/li&gt;
                            &lt;li&gt;&lt;a href=&quot;#&quot;&gt;iPhone 8plus&lt;/a&gt;&lt;/li&gt;
                         &lt;/ul&gt;
                      &lt;/div&gt;
               &lt;?php } } ?&gt; 
            &lt;/div&gt;
        &lt;/div&gt;
     &lt;/div&gt;
   &lt;?php } } ?&gt; 
  &lt;/div&gt;
  </code></pre>
     
  <p>These 3 tables are linked with eachother</p>