Bug #14220 Updated: break doesn't stop foreach from iterating over array
| From: | mfischer@php.net | Date: | Mon, 26 Nov 2001 07:59:54 +0000 |
| Subject: | Bug #14220 Updated: break doesn't stop foreach from iterating over array | ||
| References: | 1 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-71624@lists.php.net to get a copy of this message | ||
ID: 14220
Updated by: mfischer
Reported By: tim.lokot@s1.com.au
Old Status: Closed
Status: Bogus
Bug Type: Output Control
Operating System: Win2K
PHP Version: 4.0.6
New Comment:
We rather call it Bogus than Goofy ;)
Previous Comments:
------------------------------------------------------------------------
[2001-11-25 23:34:36] tim.lokot@s1.com.au
Code was goofy .... only been looking at for a few days wondering what was going on
------------------------------------------------------------------------
[2001-11-25 23:18:48] tim.lokot@s1.com.au
I'm running the following function in conjunction with the DOM XML stuff to create a SAX
parser. Trouble is that the following code doesn't seem to stop iterating over the $startTags
array when it hits the break command.
function startElement ($parser, $name, $attrs)
{
global $startTags, $xmlPath, $htmlContent, $monthWords;
$xmlPath .= "/$name";
foreach ($startTags as $tag => $value)
{
if (substr($xmlPath, strlen($xmlPath) - strlen($tag), strlen($tag)) == $tag)
{
$htmlContent .= $startTags[$tag];
if ($name == "url")
{
if (isset ($attrs["target"]))
{
$htmlContent .= " target=\"$attrs[target]\"";
}
$htmlContent .= " href=\"$attrs[page]\">";
break; // Stop iterating through tags
}
else if ($tag == "events/date")
{
$htmlContent .= "<div class=\"hdr2\">" .
$monthWords[$attrs["month"]] . ", $attrs[year]</div></div>\n<div
class=\"content\">";
}
}
}
}
An exmaple array for $startTags is as follows:
$startTags = array (
"content/section" => "<div class=\"content\">",
"text" => "<div class=\"txt2\">",
"list" => "<ul class=\"listtext\">",
"list/item" => "<li>",
"item" => "junk"
);
If you were trying to match up the item tag, then the loop would actually print out the value of
list/item and item, instead of breaking after it found list/item.
This also assumes that the xml for this match is like this
<list>
<item>point 1</item>
<item>point 2</item>
</list>
------------------------------------------------------------------------
Edit this bug report at http://bugs.php.net/?id=14220&edit=1