Use isset() or empty() to check if a variable exists or is not empty before adding it to an array.
Use array_filter() to remove unwanted values from arrays.