Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Change while loops with foreach for performance

  • Loading branch information...
commit dd29f897a617515b105e10fd100c28398247130b 1 parent b7b732c
acidvertigo authored August 15, 2011
13  catalog/admin/includes/functions/database.php
@@ -52,15 +52,13 @@ function tep_db_query($query, $link = 'db_link') {
52 52
   }
53 53
 
54 54
   function tep_db_perform($table, $data, $action = 'insert', $parameters = '', $link = 'db_link') {
55  
-    reset($data);
56 55
     if ($action == 'insert') {
57 56
       $query = 'insert into ' . $table . ' (';
58  
-      while (list($columns, ) = each($data)) {
  57
+		foreach($data as $columns) {
59 58
         $query .= $columns . ', ';
60 59
       }
61 60
       $query = substr($query, 0, -2) . ') values (';
62  
-      reset($data);
63  
-      while (list(, $value) = each($data)) {
  61
+      foreach($data as $value) {
64 62
         switch ((string)$value) {
65 63
           case 'now()':
66 64
             $query .= 'now(), ';
@@ -76,7 +74,7 @@ function tep_db_perform($table, $data, $action = 'insert', $parameters = '', $li
76 74
       $query = substr($query, 0, -2) . ')';
77 75
     } elseif ($action == 'update') {
78 76
       $query = 'update ' . $table . ' set ';
79  
-      while (list($columns, $value) = each($data)) {
  77
+	  foreach($data as $columns => $value) {
80 78
         switch ((string)$value) {
81 79
           case 'now()':
82 80
             $query .= $columns . ' = now(), ';
@@ -145,8 +143,7 @@ function tep_db_prepare_input($string) {
145 143
     if (is_string($string)) {
146 144
       return trim(stripslashes($string));
147 145
     } elseif (is_array($string)) {
148  
-      reset($string);
149  
-      while (list($key, $value) = each($string)) {
  146
+      foreach($string as $key => $value) {
150 147
         $string[$key] = tep_db_prepare_input($value);
151 148
       }
152 149
       return $string;
@@ -154,4 +151,4 @@ function tep_db_prepare_input($string) {
154 151
       return $string;
155 152
     }
156 153
   }
157  
-?>
  154
+?>

0 notes on commit dd29f89

Please sign in to comment.
Something went wrong with that request. Please try again.