Why does this code echo Yes.
even though variables are not equal!
$a = '0e462097431906509019562988736854';
$b = '0e830400451993494058024219903391';
if( $a == $b ) echo 'Yes.';
else echo 'No!';
In String, the == operator is used to comparing the reference of the given strings, depending on if they are referring to the same objects. When you compare two strings using == operator, it will return true if the string variables are pointing toward the same java object. Otherwise, it will return false .
Both equals() method and the == operator are used to compare two objects in Java. == is an operator and equals() is method. But == operator compares reference or memory location of objects in a heap, whether they point to the same location or not.
Algorithm. Define a string and take the string as input form the user. Two loops will be used to find the duplicate characters. Outer loop will be used to select a character and then initialize variable count by 1 its inside the outer loop so that the count is updated to 1 for every new character.
Both will treated as numbers, and PHP had limitations in number storage before. So check that.
Try to use '==='. it will check the type also, so those will not convert to numbers.
Refer this question and its answers.
You want strcmp, not the equality operator.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With