0

I can't seem to figure out how to loop a variable check. What I am trying to do is something like checking those two variables but in a loop

if(isset($_GET['action'])){
    $action = $_GET['action'];
}
else{
    $action = NULL;
}

if(isset($check)){
    $check = $check;
}
else{
    $check = NULL;
}

I want to do something like this or more effiecient if possible

$variables = array($_GET['action'], $check);
$define = array($action, $check);

foreach($variables as $variable){
 if(isset($variable){
   $variable = $define;
 }
}

I want it to show no errors while I have error_reporting(E_ALL) open Could someone help me with this?

4

1 回答 1

1

如果未设置变量,您的第一行将导致警告:

$variables = array($_GET['action'], $check);    // here you are possibly using unset variables

如果你想写得更短一点,你可以使用三元运算符,但仅此而已:

$action = isset($_GET['action']) ? $_GET['action'] : NULL;
$check = isset($check) ? $check : NULL;

我认为没有更有效的方法可以一次检查普通变量和超级全局变量的组合。

于 2012-05-31T15:47:40.473 回答