1

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!

2
  • 1
    try var_dump($array[7]); and var_dump('[1000137d]');... It will give you both value and type (to see why it may be different)... Commented May 25, 2010 at 19:02
  • 1
    aha, string(12) " [1000137d]" string(10) "[1000137d]" . YES! I trimmed off the spaces and now it works! Thanks man! Commented May 25, 2010 at 19:04

1 Answer 1

3

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 ;)

Sign up to request clarification or add additional context in comments.

2 Comments

aha, string(12) " [1000137d]" string(10) "[1000137d]" . YES! I trimmed off the spaces and now it works! Thanks man!
@user296516: You can click the check mark next to the answer to accept it as the correct answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.