You can move the HTML building to an external interface and send JSON data to the user through AJAX and javascript.
It may also allow you to send only certain pieces of data (depending on your html layout), so they can be dynamically tested if necessary (e.g. google / bing search).
I know that I did not answer the question directly. This is because the code that you have is probably the fastest that it can do (in PHP) without silly little optimizations that would only make it difficult to read / maintain the code (probably only save a few percent).
EDIT: looking at it again, I'm sure your code is actually just checking data from an external source in JSON. You could probably completely remove this code if the JavaScript script worked with the HTTP message and processed the data. This eliminates the need to run this PHP code.
EDIT 2: after reading your comment that this is a rollback to disable JavaScript, I looked at the code you are currently doing. It seems to translate to implode .
//declared this functions somewhere function tr_build( $row_value ) { $tablerow .= "<tr>\n"; if( $row_value ) { $tablerow .= "<td>".implode( "</td><td>", $row_value )."</td>"; } $tablerow .= "\n</tr>\n"; return $tablerow; } //this replaces the double loop if( $row ) { $tablerows = "<tr>\n".implode( "\n</tr>\n<tr>\n", array_map( "tr_build", $row ) )."\n</tr>\n" } else { $tablerows = ""; }
source share