Upgrade PHP 7.1.x to 7.2.x

Follow me!

If you like this article, go ahead and follow me on Twitter:

Follow @getButterfly

When you are upgrading a WordPress plugin or theme to be compatible with PHP 7.2.x, here is a pattern on how to update while = each() loops to foreach() loops.

Case 1: Missing $value

reset($array);
while (list($key, ) = each($array)) {

Update to:

foreach(array_keys($array) as $key) {

Case 2: Missing $key

reset($array);
while (list(, $value) = each($array)) {

Update to:

foreach($array as $value) {

Case 3: Not missing anything

reset($array);
while (list($key, $value) = each($array)) {

Update to:

foreach($array as $key => $value) {

👋 Added by Ciprian on Thursday, February 15, 2018 in Blog. Last modified on Thursday, February 15, 2018.

Contribute!

Contribute to this article by sharing your opinion on Twitter:

Unlimited Automated Page Speed Monitoring & Tracking.
Use SpeedFactor to track your website. It’s simple and reliable.
See how real people experience the speed of your website. Then find (and fix) your web performance problems.
Get Started
Privacy Policy