Use filter_var_array on whole array, or inside iteration 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 '&lt;p&gt;' . $sql_row['first_name'] . $sql_row['last_name'] . '&lt;/p&gt;';
}


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 '&lt;p&gt;' . $sql_row['first_name'] . $sql_row['last_name'] . '&lt;/p&gt;';
}
Is this really the bottleneck in you application? If not choose the readable one. See Effective Java, 2nd Edition, Item 55: Optimize judiciously I know that this is a Java book but this chapter (and many others) is useful for every developer.

Some other notes:


I'd call the filtered variable something which shows that the data has been filtered, like $filtered_row. It would improve readability and help maintainers.
The code prints the first name and the last name without any separator character. I'd consider printing a separator there:

print '&lt;p&gt;' . $sql_row['first_name'] . ' ' . $sql_row['last_name'] . '&lt;/p&gt;';

If you use only the first_name and the last_name maybe you should only filter these fields not the whole array. (I don't know whether it contains other values or not.)
Consider memory usage too. If I'm right the first one have to store the input and output array in the memory during the filtering which needs two times of the array size of memory temporarily. In the second case it's much smaller since it filters only one row at a time so it needs memory for the array once and two times of the size of a row during the filtering.