I'm not sure what you're trying to do with your code.
You check if its empty, and then try to set $err
to a value by concentrating an empty value.
Perhaps this is more likely what you want.
// Ternary operator
$err = empty($data['key']) ? "empty key" : '';
# -----------IF-----------------THEN ---- ELSE
// Ternary operator (nesting) (not recommended)
// Changing empty() to isset() you must rewrite the entire logic structure.
$err = empty($data) ? 'empty' : is_numeric($data) ? $data : 'not numeric';
# ---------IF--------- THEN -------ELSEIF-----------THEN-----ELSE
// Null Coalescing operator ?? available in PHP 7.
$err = $data['key'] ?? 'empty value';
# ---- IF ISSET USE --- ELSE value
// Nesting
$err = $data['key'] ?? $_SESSION['key'] ?? $_COOKIE['key'] ?? 'no key';
# IF ISSET USE -- IF ISSET USE ------ IF ISSET USE ------ELSE