Reputation: 5913
I have a form which is posting an array which looks like this:
Array
(
[SearchForm] => Array
(
[query] => Eg: 2 Bedroom Flat Chelsea
[rent] => 1
[share] => 0
[short] => 1
[price_min] => 50
[price_max] => 100
)
[yt0] => Search
)
I want to check if the value for $_REQUEST['SearchForm']['price_min']
is not empty, and is an integer. I am using:
if (($_REQUEST['SearchForm']['price_min'] != "") && (is_int($_REQUEST['SearchForm']['price_min']))){
...
}
The is_int
is returning false (the if statement is not being executed)
Any ideas why?
Upvotes: 1
Views: 131
Reputation: 91734
If the result comes from a posted html form, the value is most likely a string.
You can use is_numeric
to check for a valid number string.
Upvotes: 0
Reputation: 11779
Because POST and GET parameters are always string, so instead of is_int use is_numeric
Upvotes: 5
Reputation: 174947
The value is probably "50"
and not 50
(it's a string). Try is_numeric()
instead of is_int()
.
Upvotes: 1