title: Why this array is not being set properly outside of foreach loop?
body: <p>I am fetching from my db using two queries and when i try to print the result inside the for each it does print all of it  but when I try to print it outside it doesn't print everything:</p>
  
  <pre><code>$arr_devices = [];
  $sql1 = "SELECT id FROM users WHERE users.name = '$company_name'"; //finding the ids of the users of this company
  if ($res = $db-&gt;query($sql1)) {
      $arr_id = $res-&gt;fetch_all(MYSQLI_ASSOC);
      foreach ($arr_id as $company_id) {
          $sql = "SELECT
          devices.id, 
          devices.serial_imei, 
          devices.serial_no, 
          devices.type_id, 
          devices.cus_id, 
          devices.sales_date,
          device_types.name,
          device_types.manufacturer,
          device_types.device_no,
          device_types.barcode,
          users.id,
          users.name as manufacturer_name
          FROM devices
          INNER JOIN device_types 
          ON device_types.id = devices.type_id
          INNER JOIN users ON device_types.manufacturer = users.id
          WHERE devices.cus_id = " . $company_id['id'] . " ";
          $result = $db-&gt;query($sql);
  
          if ($result-&gt;num_rows &gt; 0) {
              $arr_devices = $result-&gt;fetch_all(MYSQLI_ASSOC);
          }
          print_r($arr_devices);  //HERE IT PRINTS EVERYTHING I AM FETCHING
      }
      print_r($arr_devices);  //HERE IT DOESNT
  }
  </code></pre>
  
  <p>See the comments in the code.</p>