Given this input: http://example.com/item.php?room=248&supply_id=18823 , the following 2 blocks should give the same result. Why not? What will I miss besides coffee?
This block gives the expected values:
if (isset($_GET['supply_id']) && isset($_GET['room'])) {
$id=validkey($_GET['supply_id']);
$room=validkey($_GET['room']);
$arr=array('s'=>$id,'r'=>$room);
}
But if I check and assignment in one step, $ id ends with 1 instead of 18823. Why?
if (isset($_GET['supply_id']) && isset($_GET['room'])) {
if($id=validkey($_GET['supply_id']) && $room=validkey($_GET['room']))
$arr=array('s'=>$id",'r'=>$room); //s=>1, r=>248
}
This is the function I use:
function validkey($value){
if(is_scalar($value)){
$value=(int)$value;
return ($value>0) ? $value : false;
}
return false;
}
source
share