diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc
index 52f574212a..d7df68ccb5 100644
--- a/core/includes/bootstrap.inc
+++ b/core/includes/bootstrap.inc
@@ -1021,7 +1021,7 @@ function _drupal_shutdown_function() {
   chdir(DRUPAL_ROOT);
 
   try {
-    while (list($key, $callback) = each($callbacks)) {
+    foreach ($callbacks as $key => $callback) {
       call_user_func_array($callback['callback'], $callback['arguments']);
     }
   }
diff --git a/core/lib/Drupal/Component/Diff/Engine/DiffEngine.php b/core/lib/Drupal/Component/Diff/Engine/DiffEngine.php
index 7885c6f00e..d5a9131e4a 100644
--- a/core/lib/Drupal/Component/Diff/Engine/DiffEngine.php
+++ b/core/lib/Drupal/Component/Diff/Engine/DiffEngine.php
@@ -201,8 +201,10 @@ protected function _diag($xoff, $xlim, $yoff, $ylim, $nchunks) {
           continue;
         }
         $matches = $ymatches[$line];
-        reset($matches);
-        while (list ($junk, $y) = each($matches)) {
+        $it = new ArrayIterator($matches);
+        while ($it->valid()) {
+          $y = $it->current();
+          $it->next();
           if (empty($this->in_seq[$y])) {
             $k = $this->_lcs_pos($y);
             $this::USE_ASSERTS && assert($k > 0);
@@ -210,7 +212,9 @@ protected function _diag($xoff, $xlim, $yoff, $ylim, $nchunks) {
             break;
           }
         }
-        while (list ($junk, $y) = each($matches)) {
+        while ($it->valid()) {
+          $y = $it->current();
+          $it->next();
           if ($y > $this->seq[$k - 1]) {
             $this::USE_ASSERTS && assert($y < $this->seq[$k]);
             // Optimization: this is a common case:
diff --git a/core/lib/Drupal/Core/Extension/ModuleInstaller.php b/core/lib/Drupal/Core/Extension/ModuleInstaller.php
index 10fabd412a..a9c2f5850d 100644
--- a/core/lib/Drupal/Core/Extension/ModuleInstaller.php
+++ b/core/lib/Drupal/Core/Extension/ModuleInstaller.php
@@ -93,8 +93,8 @@ public function install(array $module_list, $enable_dependencies = TRUE) {
       }
 
       // Add dependencies to the list. The new modules will be processed as
-      // the while loop continues.
-      while (list($module) = each($module_list)) {
+      // the foreach loop continues.
+      foreach ($module_list as $module => $value) {
         foreach (array_keys($module_data[$module]->requires) as $dependency) {
           if (!isset($module_data[$dependency])) {
             // The dependency does not exist.
@@ -333,9 +333,9 @@ public function uninstall(array $module_list, $uninstall_dependents = TRUE) {
 
     if ($uninstall_dependents) {
       // Add dependent modules to the list. The new modules will be processed as
-      // the while loop continues.
+      // the foreach loop continues.
       $profile = drupal_get_profile();
-      while (list($module) = each($module_list)) {
+      foreach ($module_list as $module => $value) {
         foreach (array_keys($module_data[$module]->required_by) as $dependent) {
           if (!isset($module_data[$dependent])) {
             // The dependent module does not exist.
diff --git a/core/lib/Drupal/Core/Extension/ThemeInstaller.php b/core/lib/Drupal/Core/Extension/ThemeInstaller.php
index db1226fa98..d7cffd57f5 100644
--- a/core/lib/Drupal/Core/Extension/ThemeInstaller.php
+++ b/core/lib/Drupal/Core/Extension/ThemeInstaller.php
@@ -121,9 +121,9 @@ public function install(array $theme_list, $install_dependencies = TRUE) {
         return TRUE;
       }
 
-      while (list($theme) = each($theme_list)) {
+      foreach ($theme_list as $theme => $value) {
         // Add dependencies to the list. The new themes will be processed as
-        // the while loop continues.
+        // the parent foreach loop continues.
         foreach (array_keys($theme_data[$theme]->requires) as $dependency) {
           if (!isset($theme_data[$dependency])) {
             // The dependency does not exist.
diff --git a/core/modules/book/src/BookOutline.php b/core/modules/book/src/BookOutline.php
index ec28d50c72..193c20f8fc 100644
--- a/core/modules/book/src/BookOutline.php
+++ b/core/modules/book/src/BookOutline.php
@@ -39,12 +39,14 @@ public function prevLink(array $book_link) {
     if ($book_link['pid'] == 0) {
       return NULL;
     }
-    // Assigning the array to $flat resets the array pointer for use with each().
     $flat = $this->bookManager->bookTreeGetFlat($book_link);
+    reset($flat);
     $curr = NULL;
     do {
       $prev = $curr;
-      list($key, $curr) = each($flat);
+      $key = key($flat);
+      $curr = current($flat);
+      next($flat);
     } while ($key && $key != $book_link['nid']);
 
     if ($key == $book_link['nid']) {
@@ -78,10 +80,11 @@ public function prevLink(array $book_link) {
    *   $book_link.
    */
   public function nextLink(array $book_link) {
-    // Assigning the array to $flat resets the array pointer for use with each().
     $flat = $this->bookManager->bookTreeGetFlat($book_link);
+    reset($flat);
     do {
-      list($key,) = each($flat);
+      $key = key($flat);
+      next($flat);
     } while ($key && $key != $book_link['nid']);
 
     if ($key == $book_link['nid']) {
diff --git a/core/modules/language/tests/src/Functional/LanguageNegotiationInfoTest.php b/core/modules/language/tests/src/Functional/LanguageNegotiationInfoTest.php
index 9133a125a2..c5e3c2c7b1 100644
--- a/core/modules/language/tests/src/Functional/LanguageNegotiationInfoTest.php
+++ b/core/modules/language/tests/src/Functional/LanguageNegotiationInfoTest.php
@@ -160,11 +160,7 @@ protected function checkFixedLanguageTypes() {
     foreach ($this->languageManager()->getDefinedLanguageTypesInfo() as $type => $info) {
       if (!in_array($type, $configurable) && isset($info['fixed'])) {
         $negotiation = $this->config('language.types')->get('negotiation.' . $type . '.enabled');
-        $equal = count($info['fixed']) == count($negotiation);
-        while ($equal && list($id) = each($negotiation)) {
-          list(, $info_id) = each($info['fixed']);
-          $equal = $info_id == $id;
-        }
+        $equal = array_keys($negotiation) === array_values($info['fixed']);
         $this->assertTrue($equal, format_string('language negotiation for %type is properly set up', ['%type' => $type]));
       }
     }
diff --git a/core/modules/system/src/Form/ModulesListForm.php b/core/modules/system/src/Form/ModulesListForm.php
index 28ff7ef4cc..c1f88a61a4 100644
--- a/core/modules/system/src/Form/ModulesListForm.php
+++ b/core/modules/system/src/Form/ModulesListForm.php
@@ -386,7 +386,7 @@ protected function buildModuleList(FormStateInterface $form_state) {
     }
 
     // Add all dependencies to a list.
-    while (list($module) = each($modules['install'])) {
+    foreach ($modules['install'] as $module => $value) {
       foreach (array_keys($data[$module]->requires) as $dependency) {
         if (!isset($modules['install'][$dependency]) && !$this->moduleHandler->moduleExists($dependency)) {
           $modules['dependencies'][$module][$dependency] = $data[$dependency]->info['name'];
diff --git a/core/modules/system/src/Tests/Module/InstallUninstallTest.php b/core/modules/system/src/Tests/Module/InstallUninstallTest.php
index f4db81e18e..bb53c4e665 100644
--- a/core/modules/system/src/Tests/Module/InstallUninstallTest.php
+++ b/core/modules/system/src/Tests/Module/InstallUninstallTest.php
@@ -72,7 +72,7 @@ public function testInstallUninstall() {
 
     // Go through each module in the list and try to install and uninstall
     // it with its dependencies.
-    while (list($name, $module) = each($all_modules)) {
+    foreach ($all_modules as $name => $module) {
       $was_installed_list = \Drupal::moduleHandler()->getModuleList();
 
       // Start a list of modules that we expect to be installed this time.
diff --git a/core/modules/views_ui/src/Form/Ajax/ViewsFormBase.php b/core/modules/views_ui/src/Form/Ajax/ViewsFormBase.php
index 375766a4c3..619b191465 100644
--- a/core/modules/views_ui/src/Form/Ajax/ViewsFormBase.php
+++ b/core/modules/views_ui/src/Form/Ajax/ViewsFormBase.php
@@ -104,7 +104,9 @@ public function getForm(ViewEntityInterface $view, $display_id, $js) {
       // Retrieve the first form from the stack without changing the integer keys,
       // as they're being used for the "2 of 3" progress indicator.
       reset($view->stack);
-      list($key, $top) = each($view->stack);
+      $key = key($view->stack);
+      $top = current($view->stack);
+      next($view->stack);
       unset($view->stack[$key]);
 
       if (array_shift($top) != $identifier) {
