Welcome Guest, Not a member yet? Register   Sign In
Validating Numeric Data with in_array()
#1

[eluser]Louis C.[/eluser]
I'd like to use in_array to determine to confirm that some data is numerical before I do things with it. But in_array() is confusing me with its output:
Code:
➜  ~  php -r 'print in_array(9, range(0, 10));'  
1%
➜  ~  php -r 'print in_array(-1, range(0, 10));'
➜  ~  php -r 'print in_array(m, range(0, 10));'
PHP Notice:  Use of undefined constant m - assumed 'm' in Command line code on line 1
1%
➜  ~  php -r 'print in_array('m', range(0, 10));'
PHP Notice:  Use of undefined constant m - assumed 'm' in Command line code on line 1
1%

Why does in_array say that both m and 'm' are contained in my numeric range?

What is the best way to determine if $number is between 1 and 10 in PHP?

Thanks,
Lou


Messages In This Thread
Validating Numeric Data with in_array() - by El Forum - 04-20-2011, 08:56 PM
Validating Numeric Data with in_array() - by El Forum - 04-21-2011, 08:32 AM
Validating Numeric Data with in_array() - by El Forum - 04-21-2011, 12:04 PM
Validating Numeric Data with in_array() - by El Forum - 04-22-2011, 06:33 AM
Validating Numeric Data with in_array() - by El Forum - 04-22-2011, 12:24 PM



Theme © iAndrew 2016 - Forum software by © MyBB