Permalink
Browse files

Change while loops with foreach for performance

  • Loading branch information...
acidvertigo committed Aug 15, 2011
1 parent b7b732c commit dd29f897a617515b105e10fd100c28398247130b
Showing with 5 additions and 8 deletions.
  1. +5 −8 catalog/admin/includes/functions/database.php
@@ -52,15 +52,13 @@ function tep_db_query($query, $link = 'db_link') {
}
function tep_db_perform($table, $data, $action = 'insert', $parameters = '', $link = 'db_link') {
- reset($data);
if ($action == 'insert') {
$query = 'insert into ' . $table . ' (';
- while (list($columns, ) = each($data)) {
+ foreach($data as $columns) {
$query .= $columns . ', ';
}
$query = substr($query, 0, -2) . ') values (';
- reset($data);
- while (list(, $value) = each($data)) {
+ foreach($data as $value) {
switch ((string)$value) {
case 'now()':
$query .= 'now(), ';
@@ -76,7 +74,7 @@ function tep_db_perform($table, $data, $action = 'insert', $parameters = '', $li
$query = substr($query, 0, -2) . ')';
} elseif ($action == 'update') {
$query = 'update ' . $table . ' set ';
- while (list($columns, $value) = each($data)) {
+ foreach($data as $columns => $value) {
switch ((string)$value) {
case 'now()':
$query .= $columns . ' = now(), ';
@@ -145,13 +143,12 @@ function tep_db_prepare_input($string) {
if (is_string($string)) {
return trim(stripslashes($string));
} elseif (is_array($string)) {
- reset($string);
- while (list($key, $value) = each($string)) {
+ foreach($string as $key => $value) {
$string[$key] = tep_db_prepare_input($value);
}
return $string;
} else {
return $string;
}
}
-?>
+?>

0 comments on commit dd29f89

Please sign in to comment.