The开发者_运维知识库re are many ways to see if a value exists using PHP. There's isset, !=false, !==false, !empty, etc. Which one will be the best (fast and accurate) one to use in the following situation?
if($_GET['test'])
...
if (isset($_GET['test'])) {
// use value
}
if(array_key_exists($_GET, "test"))
array_key_exists return true if a key exists in an array, isset will return true if the key/variable exists and is not null.
Isset is probably best because it checks if the url contains a "?test=". If you want to make sure it is not empty you have to check further.
I'd go with the php5 one type of get:
$test = filter_input(INPUT_GET, 'test', FILTER_SANITIZE_STRING);
if($test){
//do something
}
Reference here, you can validate and sanitize with them. you can use "filter_input_array" for the full input types.
isset function only checks for its avaliability you have to use empty function too in order to see if it is set and not empty also as:
if (isset($_GET['test']) && !empty($_GET['test'])) {
精彩评论