I have a MySQL result set in a PHP multidimensional array.
I want to iterate through it and output it sanitized. Considering the two alternatives below, are there any performance differences?
filter_var_array on the whole result set before iterating:
$sql_rows = filter_var_array($sql_rows, FILTER_SANITIZE_FULL_SPECIAL_CHARS);
foreach ($sql_rows as $sql_row) {
print '<p>' . $sql_row['first_name'] . $sql_row['last_name'] . '</p>';
}
filter_var_array on each row inside the iteration:
foreach ($sql_rows as $sql_row) {
$sql_row = filter_var_array($sql_row, FILTER_SANITIZE_FULL_SPECIAL_CHARS);
print '<p>' . $sql_row['first_name'] . $sql_row['last_name'] . '</p>';
}
microtime()
s around each and see how long it took to perform each and then use whichever had better performance. \$\endgroup\$ – mseancole Jul 11 '12 at 13:34