Jump to content

Issues when comparing data from different XML structures


Mzor

Recommended Posts

This is something I've never run into before and am having issues with:

 

I have two different simplexml objects that I have data in. I have two pieces of data from them, both of which are:

 

"BC".

 

That's all. I've used strlen to check their length.

 

Now, when I go:

 

$data1->name == "BC"

 

it comes out as true.

 

When I go:

 

$data2->name == "BC"

 

it comes out as true.

 

When I go:

 

$data1->name == $data2->name

 

it comes out false.

 

Whaaat? I simply don't understand why it's doing this. the strings have the same lengths, they both equal the same thing however they don't equal each other? I'm guessing it's because they're from different structures, that's all I can think of...

 

Note that those were examples of the structures I use but it's the same thing.

No, the issue here is that I'm doing a comparison.

 

if($data1->name == $data2->name){

  //blah blah blah

}

 

I should have elaborated on that, but the issue can be shown like this:

 

if($data1->name == "BC"){
   //this returns true and this code is executed
}


if($data2->name == "BC"){
   //this ALSO returns true and this code is executed
}

if($data1->name == $data2->name){
   //this code does not happen because even though both pieces of data were shown to be "BC", for some reason the comparison comes out false
}

 

I have no idea why it's doing this, but it is...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.