Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>As I have been finding out, a lot of these helper functions are really necessary because PHP isn't strongly typed. I posted a <a href="https://stackoverflow.com/questions/3295128/is-this-an-ok-test-to-see-if-a-variable-is-set">similar question</a> (although not <em>that</em> similar) about isset earlier this week. One thing to note is that <strong>PHP will change your string to its integer value</strong> for comparisons during some instances (when there are mixed types). This can't be overlooked. I think this is a strong case for <code>is_numeric</code></p> <p>from <a href="http://php.net/manual/en/language.operators.comparison.php" rel="nofollow noreferrer">PHP Manual</a></p> <blockquote> <p>If you compare a number with a string or the comparison involves numerical strings, then each string is converted to a number and the comparison performed numerically. These rules also apply to the switch statement. The type conversion does not take place when the comparison is === or !== as this involves comparing the type as well as the value.</p> </blockquote> <p>Another thing to think about is that "what is 0" in PHP. It means a lot. It's not always numeric. It may be a numeric string, boolean false, integer, etc... This is why those helper functions exist.</p> <p>To add to my answer:</p> <p>change your example:</p> <pre><code>$whatami='beast'; ($whatami&lt;5) ? echo 'less than 5' : echo 'more than 5'; </code></pre> <p>PHP would change 'beast' to its integer equivalent and then do the comparison. This would give unintended results. If you really wanted something similar, you'd have to wrap it in another conditional:</p> <pre><code>$whatami='beauty'; if(is_numeric($whatami){ ($whatami&lt;5) ? echo 'less than 5' : echo 'more than 5'; } else { exit('what, am I not pretty enough for a beast?'); } </code></pre> <p>Then you would get your intended result (as weird as it may be).</p>
    singulars
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. 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