EDIT:
if(array_key_exists($errcode, $Errors)){
$Data['status'] = -1;
$Data['err'] = array(
"err_code" => $errcode,
"err_str" => $Errors[$errcode]
);
}
I'm having a harsh time figuring out if a key exists in an array, I've tried using array_key_exists method, but no luck! I've also tried empty($array[$key]) which seems to return the same generic error rather than the specific one.
Calling err(null, 3) will output:
{
"status": -1,
"err": {
"err_code": null,
"err_str": "Generic error"
}
}
I've tried using the array_key_exists method which returns a bool but it doesn't seem to work, why is this?
My site should output error 5: Invalid
//Errors ENUM
$Errors = array(
0 => "Cannot parse <GameID>",
1 => "Invalid steam session",
2 => "Invalid <GameID>, non-numeric",
3 => "SQL Connection refused",
4 => "SQL Query error",
5 => "invalid <GameID>"
);
function err($status, $errcode){
if(isset($errcode)){
if($Errors[$errcode] != null){
$Data['status'] = -1;
$Data['err'] = array(
"err_code" => $errcode,
"err_str" => $Errors[$errcode]
);
} else {
$Data['status'] = -1;
$Data['err'] = array(
"err_code" => null,
"err_str" => "Generic error"
);
}
} else {
$Data['status'] = $status;
$Data['err'] = array(
"err_code" => null,
"err_str" => null
);
}
echo(json_encode($Data, 128 | 32));
}