note 38141 deleted from control-structures.foreach by tomsommer

From: Date: Wed, 18 Aug 2004 19:31:40 +0000
Subject: note 38141 deleted from control-structures.foreach by tomsommer
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-74913@lists.php.net to get a copy of this message
Note Submitter: JFrasca at caldel dot com ---- If you ever find yourself wanting to create a table based on the contents of a multi-dimensional array, this: <?php $output = ""; foreach ($ary AS $val) { $output .= " <tr>\n" ." <td>"; $output .= implode($val, "</td>\n <td>"); $output .= "</td>\n" ." </tr>\n"; } echo $output; unset ($output); ?> is much faster than this: <?php $output = ""; foreach ($ary AS $val) { $output .= " <tr>\n"; foreach ($val AS $val2) { $output .= " <td>$val2</td>\n"; } $output .= " </tr>\n"; } echo $output; unset ($output); ?> Also note that I am compiling it in a variable before echoing it. I found this was faster than echoing each line seperately.

« previous php.notes (#74913) next »