Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>To add to Michael's answer, the reason why you should not use == for string comparison (hopefully this will help you navigate similar difficulties in the future) is that when you call a simple == on an object (such as a string, or really anything other than an int, double, float, char, long, short, or boolean, in most languages), what you're really comparing is the address in memory of each object, that is, the pointer value.</p> <p>This is useful if you want to know if two variables are referencing the same object, but not so useful if you want to know if two objects are identical. So this is true:</p> <pre><code>$string_a = $some_string; $string_b = $some_string; $string_a == $string_b; </code></pre> <p>but this is not:</p> <pre><code>$string_a = getUserInput(); # user types in "hello" $string_b = getUserInput(); # user types in "hello" $string_a == $string_b; </code></pre> <p>and this may be true depending on the language you're in, if it stores string literals in memory independently of the user-defined variables to which they are attached:</p> <pre><code>$string_a = "hello"; $string_b = "hello"; $string_a = $string_b; </code></pre> <p>So unless you're checking to see if two objects are in fact the same object, and not merely identical, use, as those before me suggested, a function to compare the two. Such a function usually goes down to the level of primitive types, which can be compared using == as you would expect, and returns true if all of those comparisons do.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload