Jeremy Newman : replace while each loops with foreach

Jeremy Newman jnewman at winehq.org
Tue Jul 30 11:16:48 CDT 2019


Module: website
Branch: master
Commit: c8a4bba855c5c92fdbd6a0ab66f749043940e257
URL:    https://source.winehq.org/git/website.git/?a=commit;h=c8a4bba855c5c92fdbd6a0ab66f749043940e257

Author: Jeremy Newman <jnewman at codeweavers.com>
Date:   Tue Jul 30 11:16:19 2019 -0500

replace while each loops with foreach

---

 include/config.php           | 4 ++--
 include/plugins/announce.php | 4 ++--
 include/utils.php            | 8 ++++----
 include/wwn.php              | 8 ++++----
 4 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/include/config.php b/include/config.php
index c3fbed8..86c65fe 100644
--- a/include/config.php
+++ b/include/config.php
@@ -41,7 +41,7 @@ class config
                 if (preg_match('/^\@/', $arr[0]))
                 {
                     // array
-                    $arr[0] = preg_replace('/\@/', '', $arr[0]); 
+                    $arr[0] = preg_replace('/\@/', '', $arr[0]);
                     $this->{$arr[0]} = preg_split('/,\s+/', $arr[1]);
                 }
                 else if (preg_match('/^\%/', $arr[0]))
@@ -50,7 +50,7 @@ class config
                     $arr[0] = preg_replace('/\%/', '', $arr[0]);
                     $this->{$arr[0]} = array();
                     $params = preg_split('/,\s+/', $arr[1]);
-                    while (list($n, $m) = each($params))
+                    foreach ($params as $n => $m)
                     {
                         list($key, $val) = preg_split('/\|/', $m, 2);
                         $this->{$arr[0]} = array_merge($this->{$arr[0]}, array($key => $val));
diff --git a/include/plugins/announce.php b/include/plugins/announce.php
index fb707a0..39bcd25 100644
--- a/include/plugins/announce.php
+++ b/include/plugins/announce.php
@@ -21,7 +21,7 @@ $title = "";
 if ($arr = file($announce))
 {
     $in_header = 1;
-    while (list($c,$val) = each($arr))
+    foreach ($arr as $c => $val)
     {
         if ($c == 0)
             $title = $html->encode(trim($arr[$c]));
@@ -42,7 +42,7 @@ if ($arr = file($announce))
             $arr[$c] = preg_replace("/AUTHORS/",
                                     "<a href=\"".$config->git_tree."/wine.git/".$tag.":\\0\">\\0</a>",
                                     $arr[$c]);
-        }           
+        }
         else if ($in_bugs)
         {
             $arr[$c] = preg_replace("/^( +)([0-9]+)/",
diff --git a/include/utils.php b/include/utils.php
index 21d5253..4876bd8 100644
--- a/include/utils.php
+++ b/include/utils.php
@@ -224,10 +224,10 @@ function get_files ($dir, $filter = null)
         array_push($files, $entry);
     }
     closedir($d);
-    
+
     //sort dir
     sort($files);
-    
+
     return $files;
 }
 
@@ -288,7 +288,7 @@ function bytes2human ($bytes)
 // search an array for a key, and optionally the value
 function in_array_key ($key, $array, $value = false)
 {
-   while (list($k, $v) = each($array))
+   foreach ($array as $k => $v)
    {
        if ($key == $k)
        {
@@ -366,7 +366,7 @@ function array_qsort (&$array, $column=0, $order=SORT_ASC, $first=0, $last= -2)
     // $order  - SORT_ASC (default) for ascending or SORT_DESC for descending
     // $first  - start index (row) for partial array sort
     // $last   - stop index (row) for partial array sort
-    
+
     if($last == -2) $last = count($array) - 1;
     if($last > $first)
     {
diff --git a/include/wwn.php b/include/wwn.php
index 7203b2f..d13957e 100644
--- a/include/wwn.php
+++ b/include/wwn.php
@@ -6,7 +6,7 @@
   by Jeremy Newman <jnewman at codeweavers.com>
 */
 
-class wwn 
+class wwn
 {
     public $mode = 'wwn';
     public $currentTag;
@@ -114,7 +114,7 @@ class wwn
         if ($limit == 0)
           $back = '<div align=center><table cellpadding=0 cellspacing=20 width="100%"><tr valign=top>'."\n";
 
-        while(list($issue,$file) = each($issues))
+        foreach ($issues as $issue => $file)
         {
             // inner counter
             $num++;
@@ -218,7 +218,7 @@ class wwn
         }
 
         $c = 0;
-        while(list($id,$sum) = each($this->summary))
+        foreach ($this->summary as $id => $sum)
         {
             $summary_box .= '<li><a href="'.$html->_web_root."/".PAGE."/".$cur."#".$sum.'" class="small">'.$sum.'</a></li>'."\n";
             $c++;
@@ -460,7 +460,7 @@ class wwn
               if (isset($this->map_array[strtolower($name)]))
               {
                 $attribs = "";
-                while(list($key,$value) = each($attrs))
+                foreach ($attrs as $key => $value)
                 {
                     $attribs .= " $key=\"$value\"";
                 }




More information about the wine-cvs mailing list