19

I have the below each() line in a PHP file on a server where I recently upgraded the PHP version from 5 to 7.

while(list($file, $info) = each($this->images))

The error below is thrown by the web server after the restart.

The each() function is deprecated. This message will be suppressed on further calls

What will be the correct way of re-writing the above line of code in PHP 7.2?

Thank you.

Don't Panic
  • 41,125
  • 10
  • 61
  • 80
BBT
  • 211
  • 1
  • 3
  • 8

1 Answers1

44

You should be able to swap out your each for a foreach in the most part.

<?php

foreach($this->images as $file => $info) {
    // ...
}
Progrock
  • 7,373
  • 1
  • 19
  • 25