Skip to content

Commit cafbb26

Browse files
bramleysamtuke
authored andcommitted
Replace while ... each() by foreach (#290)
1 parent 6e2859a commit cafbb26

30 files changed

+64
-75
lines changed

public_html/lists/admin/actions/export.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
$row_delim = "\n";
8888

8989
if (is_array($_SESSION['export']['cols'])) {
90-
while (list($key, $val) = each($DBstruct['user'])) {
90+
foreach ($DBstruct['user'] as $key => $val) {
9191
if (in_array($key, $_SESSION['export']['cols'])) {
9292
if (strpos($val[1], 'sys') === false) {
9393
fwrite($exportfile, $val[1].$col_delim);
@@ -168,11 +168,11 @@
168168
}
169169
++$done;
170170
reset($_SESSION['export']['cols']);
171-
while (list($key, $val) = each($_SESSION['export']['cols'])) {
171+
foreach ($_SESSION['export']['cols'] as $key => $val) {
172172
fwrite($exportfile, strtr($user[$val], $col_delim, ',').$col_delim);
173173
}
174174
reset($attributes);
175-
while (list($key, $val) = each($attributes)) {
175+
foreach ($attributes as $key => $val) {
176176
$value = UserAttributeValue($user['id'], $val['id']);
177177
fwrite($exportfile, quoteEnclosed($value, $col_delim, $row_delim).$col_delim);
178178
}

public_html/lists/admin/actions/import1.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888
}
8989
}
9090

91-
while (list($email, $data) = each($user_list)) {
91+
foreach ($user_list as $email => $data) {
9292
//# a lot of spreadsheet include those annoying quotes
9393
$email = str_replace('"', '', $email);
9494
set_time_limit(60);

public_html/lists/admin/actions/import2.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@
116116
$user['systemvalues'] = $system_values;
117117
reset($_SESSION['import_attribute']);
118118
$replace = array();
119-
while (list($key, $val) = each($_SESSION['import_attribute'])) {
119+
foreach ($_SESSION['import_attribute'] as $key => $val) {
120120
if (!empty($values[$val['index']])) {
121121
$user[$val['index']] = addslashes($values[$val['index']]);
122122
$replace[$key] = addslashes($values[$val['index']]);
@@ -437,7 +437,7 @@
437437
reset($_SESSION['lists']);
438438
$addition = 0;
439439
$listoflists = '';
440-
while (list($key, $listid) = each($_SESSION['lists'])) {
440+
foreach ($_SESSION['lists'] as $key => $listid) {
441441
$query = 'replace INTO '.$tables['listuser']." (userid,listid,entered) values($userid,$listid,now())";
442442
$result = Sql_query($query, 1);
443443
// if the affected rows is 2, the user was already subscribed
@@ -475,7 +475,7 @@
475475
//add this user to the groups identified
476476
reset($groups);
477477
$groupaddition = 0;
478-
while (list($key, $groupid) = each($groups)) {
478+
foreach ($groups as $key => $groupid) {
479479
if ($groupid) {
480480
$query = sprintf('replace INTO user_group (userid,groupid,type) values(%d,%d,%d)', $userid,
481481
$groupid, $_SESSION['grouptype']);

public_html/lists/admin/addprefix.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
include 'structure.php';
1515

16-
while (list($table, $value) = each($DBstruct)) {
16+
foreach ($DBstruct as $table => $value) {
1717
if ($table != $tables[$table]) {
1818
Sql_Verbose_Query("drop table if exists $tables[$table]", 0);
1919
Sql_Verbose_Query("alter table $table rename $tables[$table]", 0);

public_html/lists/admin/admin.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
if ($id) {
8484
echo '<div class="actionresult">';
8585
reset($struct);
86-
while (list($key, $val) = each($struct)) {
86+
foreach ($struct as $key => $val) {
8787
$a = $b = '';
8888
if (strstr($val[1], ':')) {
8989
list($a, $b) = explode(':', $val[1]);
@@ -100,7 +100,7 @@
100100
// Sql_Query("update {$tables["admin"]} set password = \"".sql_escape($_POST['password'])."\" where id = $id");
101101
}
102102
if (isset($_POST['attribute']) && is_array($_POST['attribute'])) {
103-
while (list($key, $val) = each($_POST['attribute'])) {
103+
foreach ($_POST['attribute'] as $key => $val) {
104104
Sql_Query(sprintf('replace into %s (adminid,adminattributeid,value)
105105
values(%d,%d,"%s")', $tables['admin_attribute'], $id, $key, addslashes($val)));
106106
}
@@ -165,7 +165,7 @@
165165
}
166166

167167
reset($struct);
168-
while (list($key, $val) = each($struct)) {
168+
foreach ($struct as $key => $val) {
169169
$a = $b = '';
170170
if (empty($data[$key])) {
171171
$data[$key] = '';

public_html/lists/admin/adminattributes.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
echo '<script language="Javascript" type="text/javascript"> document.write(progressmeter); start();</script>';
88
}
99
flush();
10-
while (list($id, $val) = each($_POST['name'])) {
10+
foreach ($_POST['name'] as $id => $val) {
1111
if (!$id && isset($_POST['name'][0]) && $_POST['name'][0] != '') {
1212
// it is a new one
1313
$lc_name = substr(preg_replace("/\W/", '', strtolower($_POST['name'][0])), 0, 10);
@@ -59,7 +59,7 @@
5959
}
6060
}
6161
if (isset($_POST['delete'])) {
62-
while (list($id, $val) = each($_POST['delete'])) {
62+
foreach ($_POST['delete'] as $id => $val) {
6363
$res = Sql_Query("select tablename,type from {$tables['adminattribute']} where id = $id");
6464
$row = Sql_Fetch_Row($res);
6565
if ($row[1] != 'hidden' && $row[1] != 'textline') {
@@ -135,7 +135,7 @@
135135
<td colspan="2"><select name="type[0]">
136136
<?php
137137
$types = array('textline', 'hidden'); //'radio','select','checkbox',
138-
while (list($key, $val) = each($types)) {
138+
foreach ($types as $key => $val) {
139139
printf('<option value="%s" %s>%s</option>', $val, '', $val);
140140
}
141141
?>

public_html/lists/admin/attributes.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
echo '<div class="panel"><div class="header"></div><div class="content">';
2020
if (isset($_POST['action'])) {
2121
if (isset($_POST['name'])) {
22-
while (list($id, $val) = each($_POST['name'])) {
22+
foreach ($_POST['name'] as $id => $val) {
2323
if (!$id && isset($_POST['name'][0]) && $_POST['name'][0] != '') {
2424
// it is a new one
2525
$lc_name = getNewAttributeTablename($_POST['name'][0]);
@@ -173,7 +173,7 @@
173173
} elseif (isset($_POST['tagaction']) && is_array($_POST['tag'])) {
174174
ksort($_POST['tag']);
175175
if (isset($_POST['tagaction']['delete'])) {
176-
while (list($k, $id) = each($_POST['tag'])) {
176+
foreach ($_POST['tag'] as $k => $id) {
177177
// check for dependencies
178178
$id = sprintf('%d', $id);
179179
if ($formtable_exists) {

public_html/lists/admin/class.image.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class imageUpload
6363
$result = array();
6464
$req = Sql_Query(sprintf('select * from image where id = %d', $fielddata[data]));
6565
$att = Sql_Fetch_Array($req);
66-
while (list($key, $val) = each($att)) {
66+
foreach ($att as $key => $val) {
6767
$result[$fielddata[name] . "." . $key] = $val;
6868
}
6969
return $result;

public_html/lists/admin/connect.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ function Error($msg, $documentationURL = '')
470470
++$GLOBALS['mail_error_count'];
471471
if (is_array($_POST) && count($_POST)) {
472472
$GLOBALS['mail_error'] .= "\nPost vars:\n";
473-
while (list($key, $val) = each($_POST)) {
473+
foreach ($_POST as $key => $val) {
474474
if ($key != 'password') {
475475
if (is_array($val)) {
476476
$GLOBALS['mail_error'] .= $key.'='.serialize($val)."\n";
@@ -1788,7 +1788,7 @@ function delimited($data)
17881788
{
17891789
$delimitedData = '';
17901790
reset($data);
1791-
while (list($key, $val) = each($data)) {
1791+
foreach ($data as $key => $val) {
17921792
$delimitedData .= $key.'KEYVALSEP'.$val.'ITEMSEP';
17931793
}
17941794
$length = strlen($delimitedData);
@@ -2044,7 +2044,7 @@ function phplist_shutdown()
20442044
.$GLOBALS['mail_error'];
20452045
$message .= "\n==== debugging information\n\nSERVER Vars\n";
20462046
if (is_array($_SERVER)) {
2047-
while (list($key, $val) = each($_SERVER)) {
2047+
foreach ($_SERVER as $key => $val) {
20482048
if (stripos($key, 'password') === false) {
20492049
$message .= $key.'='.serialize($val)."\n";
20502050
}
@@ -2171,7 +2171,7 @@ function printarray($array)
21712171
if (!is_array($array)) {
21722172
return;
21732173
}
2174-
while (list($key, $value) = each($array)) {
2174+
foreach ($array as $key => $value) {
21752175
if (is_array($value)) {
21762176
echo $key.'(array):<blockquote>';
21772177
printarray($value); //recursief!!

public_html/lists/admin/date.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ public function showInput($name, $fielddata, $value, $document_id = 0)
150150
</select>
151151
<select name="' .$name.'[month]">';
152152
reset($this->months);
153-
while (list($key, $val) = each($this->months)) {
153+
foreach ($this->months as $key => $val) {
154154
$sel = '';
155155
if ($key == $month) {
156156
$sel = 'selected="selected"';

0 commit comments

Comments
 (0)