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.

0

1 Answer 1

44

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

<?php

foreach($this->images as $file => $info) {
    // ...
}
2
  • Thank you Progrock. Your solution has worked for me.
    – BBT
    Jul 11, 2018 at 7:20
  • One aims to please ;)
    – Progrock
    Jul 11, 2018 at 7:21

Not the answer you're looking for? Browse other questions tagged or ask your own question.