Roger Travis
Roger Travis

Reputation: 8538

crazy things with PHP array

A very strange thing, I have an array where element 7 is '[1000137d]', but when I try to compare it by using if ( $array[7] == '[1000137d]' ) it will return a negative.

echo $array[7];
echo '<br>';
echo '[1000137d]';
echo '<br>';
echo md5($array[7]);
echo '<br>';
echo md5('[1000137d]');

this code would echo out:

[1000137d]
[1000137d]
ca9983334e720042e3a6cbb1dd6b7fd2
3b1c21e661bd7d38deda1f4a45eaa23b 

as you can see $array[7] is identical to [1000137d], yet their md5's differ. what do you think might be the problem?

Thanks!

Upvotes: 1

Views: 156

Answers (1)

salathe
salathe

Reputation: 51950

There may be some trailing whitespace, to give one example, that gives no apparent difference. Try var_dump($array[7]) to see if that outputs the expected string(10) "[1000137d]".

Edit: wow I'm slow (in more ways than one ;)

Upvotes: 3

Related Questions