0

I have some code which is no longer compatible with PHP 8.1 because of depracation of each() in PHP 8. Could you help me convert this block one compatible with php 8?

while ((list($key, $category) = each($this->selected_categories)) || ($i % $columns != 0)) {
    if ($category && !($category->totalItemCount() || $this->params->get('config.show_empty_categories', false))) 
        continue;
    if ($i % $columns == 0) 
        echo ($i > 0 ? '</div><div class="row">' : '<div class="row first-row">');
    $firstcell = ($i % $columns == 0) ? 'first-cell' : null;
    echo '<div class="width'.intval(100 / $columns).' '.$firstcell.'">'.$this->partial('category', compact('category')).'</div>';
    $i++;
}
Barmar
  • 741,623
  • 53
  • 500
  • 612
  • Could you explain the logic? I don't understand why you'd want the loop to continue past the end of `$this->selected_categories` when `$i % $columns != 0` is true. – Barmar Jul 04 '22 at 22:41
  • FYI it was deprecated in 7.2, and removed entirely in 8.0. – Barmar Jul 04 '22 at 22:48

0 Answers0