Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>There is a big difference between "can evaluate if a certain variable is a number or not" and "evaluate if a certain variable is a positive number". Using the comparison signs require you to test it twice (Both <code>&gt;</code> &amp; <code>&lt;=</code> or <code>&gt;=</code> &amp; <code>&lt;</code>) and may not be immediately obvious. <code>is_numeric</code> means you only need a single test and makes it quite obvious what you are doing.</p> <p>Also, a string will evaluate as 0, meaning it throws your idea out. Stick with the proper commands :)</p> <p><strong>As per comment:</strong> Well, in this case, you are asking for comparing <code>is_numeric</code> against a test for positive numbers, excluding 0. This is not the intent for <code>is_numeric</code>, so naturally it may not be necessary. If you do a mathematical check that involves 0 as the answer or as part of the range, you will need <code>is_numeric</code>, otherwise you won't need it. The first part of your question asks a different question, so:</p> <p><em>It seems that simple comparison signs >,>= and their reverse components can evaluate if a certain variable is a number or not</em> - <strong>Incorrect</strong></p> <p><em>Are there cases where <code>is_numeric()</code> usage is necessary for positive values (number >0)?</em> - <strong>No</strong></p> <p><em>It seems that using comparison signs above would determine if the variable is numeric</em> - <strong>No. They can determine if a variable is either <em>a non-zero number</em> or <em>unknown</em>, not numeric.</strong></p>
 

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