Best practices in web development: use of empty
The empty() function in PHP is used to check if a variable exists and if its value is considered empty. It is a good practice to make your code not to break when you receive variable values that you have to secure It returns true if the variable does not exist or if its value is one of the following: As empty checks that the variable exists, it would save us this statement: To this one which is much more abbreviated: For an array we should also add the check if it is an array: And you could also use it in a ternary: But in these cases, […].