I am new to php and this little bugger has been eating up my day, perhaps it’s due to some property of php I am unaware of?
As part of some code for getting some data out of an xml file (using the event based Expat parser), I have the following code
$xmlFields;
$fieldName = "";
…………… some other code …………
function char($parser,$data)
{
global $xmlFields, $fieldName;
if($fieldName) {
if($fieldName == "brandName" || "oeNumber" || "articleId" || "quantityPerPackingUnit" || "attrName") {
$xmlFields[$fieldName] = $data;
echo $data;
}
}
}
I try to echo $xmlFields["brandName"] for example, and nothing is printed.
1) I know that $xmlFields["brandName"] is non-empty because echo $data actually returns something.
2) If I change to $xmlFields[$fieldName] = 'some string';
then echo $xmlFields["brandName"] will print ‘some string’
so why won’t it print $xmlFields["brandName"]?
Thanks in advance,
Yazan
The following expression
is parsed as
Notice that your equality check is separated from the other checks. In this case, the expression always evaluates to
true.You can use an array for this case: