0

I have an IF-Statement which is ALWAYS true. It is not related to other (similar) issue I found here, that's why I posted it again.

Please see:

$us1 = $res->C147;
$us2 = $res->C153;
    if($us1 == $us2){
        $resArr[$i]["updated"] = "SAME";
    }else{
        $resArr[$i]["updated"] = "DIFFERENT";
    }

No matter what I enter for $us1 and/or $us2 it will always be "SAME".

$res->C147 & $res->C153 are 3 letter strings such as "BRR" or "TOW", coming from an XML. Not sure if relevant:

<C147>LIE</C147>
<C150>2</C150>
<C153>BRR</C153>

Any ideas?

Michael Berkowski
  • 267,341
  • 46
  • 444
  • 390
PrimuS
  • 2,505
  • 6
  • 33
  • 66
  • 2
    Consider explicitly casting to string: `$us1 = (string) $res->C147; $us2 = (string) $res->C153;` if you're getting these from XML using SimpleXML or XMLReader – Mark Baker Jun 08 '14 at 12:27
  • 1
    Your `if` statement is fine. The values must be different. – George Jun 08 '14 at 12:28
  • 1
    Please post the output of `var_dump($us1, $us2);` and the code where you originally set those variables. – Michael Berkowski Jun 08 '14 at 12:28
  • 5
    I bet 30$ that your XML reader is (silently) failing to parse C147 and C153 and is populating both `$res->C147` and `$res->C153` with an empty string. – Shoe Jun 08 '14 at 12:29
  • 3
    I'd bet that the values are `SimpleXML` objects and not actually strings... – deceze Jun 08 '14 at 12:30
  • See var_dump:`object(SimpleXMLElement)#45 (1) { [0]=> string(3) "JOS" } object(SimpleXMLElement)#46 (1) { [0]=> string(3) "JOS" } object(SimpleXMLElement)#87 (1) { [0]=> string(3) "JOS" } object(SimpleXMLElement)#45 (1) { [0]=> string(3) "LIE" }` so yes, they are objects, but what difference does that make for the statement? – PrimuS Jun 08 '14 at 12:32
  • `if((string) $res->C147 == (string) $res->C153){` did the trick... – PrimuS Jun 08 '14 at 13:00

0 Answers0