PHP Noob question => operator usage
Posted: Mon Mar 13, 2006 2:00 pm
Hi,
I've recently started learning PHP. I'm trying to grok the XML stuff and I'm probably getting ahead of myself, but we learn by just trying stuff, right?
Anyways, I'm looking at the article "CLXII. XML Parser Functions." In the final example down towards the bottom, 3. External Entity Example, there's this bit of code:
function startElement($parser, $name, $attribs)
{
echo "<<font color=\"#0000cc\">$name</font>";
if (count($attribs)) {
foreach ($attribs as $k => $v) {
echo " <font color=\"#009900\">$k</font>=\"<font
color=\"#990000\">$v</font>\"";
}
}
echo ">";
}
I'm confused about the foreach($attribs as $k => $v) bit...
I don't know what the => in this context is doing. I understand that ultimately $v contains the value and k$ contains the attribute name because I see that in the result. I know that => in this context has something to do with the $attribs array, but I don't understand that line of code. Can someone explain to me what's going on?
Thanks!!
I've recently started learning PHP. I'm trying to grok the XML stuff and I'm probably getting ahead of myself, but we learn by just trying stuff, right?
Anyways, I'm looking at the article "CLXII. XML Parser Functions." In the final example down towards the bottom, 3. External Entity Example, there's this bit of code:
function startElement($parser, $name, $attribs)
{
echo "<<font color=\"#0000cc\">$name</font>";
if (count($attribs)) {
foreach ($attribs as $k => $v) {
echo " <font color=\"#009900\">$k</font>=\"<font
color=\"#990000\">$v</font>\"";
}
}
echo ">";
}
I'm confused about the foreach($attribs as $k => $v) bit...
I don't know what the => in this context is doing. I understand that ultimately $v contains the value and k$ contains the attribute name because I see that in the result. I know that => in this context has something to do with the $attribs array, but I don't understand that line of code. Can someone explain to me what's going on?
Thanks!!