note 94518 deleted from function.array-reduce by danbrown
| From: | danbrown@php.net | Date: | Tue, 10 Nov 2009 15:40:31 +0000 |
| Subject: | note 94518 deleted from function.array-reduce by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-162709@lists.php.net to get a copy of this message | ||
Note Submitter: Jon P
----
This works as you want:
$html = "";
function reduceToTable($html, $p) {
global $html;
$html .= "<TR><TD><a
href=\"$p.html\">$p</a></td>\n";
return $html;
}
$list = Array("page1", "page2", "page3");
$tab = array_reduce($list, "reduceToTable");
echo "<table>\n". $tab . "</table>\n";
The output does not have any preceeding 0. This was being caused by the .= on a variable that
doesn't exist the first time through.