title: Adding elements to an array from a sql query
body: <p>I'm trying to add the returned items from the query to the array. I have already searched similar topics, but I have not been able to properly modify the code to get the table I need.
  I am trying to add to the array those elements that contain a category (i.e. those that are not empty). I've used the count function before, but to no avail. When I display an array outside the loop, it shows me all the elements, including the empty ones. I suppose I have a poorly constructed conditional. How should I fix the code to make it work properly?
  Thanks for any help</p>
  <pre><code>public static function findEmpikCategoryFromEmpikCategories($colectionLilante) {
              // print_r($colectionLilante);
              $empikCategory = [];
      
              $pdo = PDOConnector::getConnection();
              
              foreach($colectionLilante as $collection)
              {
                  // print_r($collection);
                  $query = &quot;SELECT empik_category FROM `empik_categories` WHERE lilante_category='$collection' LIMIT 1&quot;;
                  // echo &quot;&lt;/br&gt;&quot;;
              
  
                  $stmt = $pdo-&gt;prepare($query);
                  $stmt-&gt;execute();
                  
                  while ($row = $stmt-&gt;fetch(PDO::FETCH_ASSOC)) {
                      // print_r($row); 
                      if($row['empik_category'])
                      {
                          $empikCategory[] = $row['empik_category'];
                      }
                                              
                  }
  
  
              }
              // echo &quot;&lt;/br&gt;&quot;;
              print_r($empikCategory);
  
              return $empikCategory;
          }
  </code></pre>