How can variables be properly defined and assigned values in PHP to avoid errors like "Undefined variable" notices?

To properly define and assign values to variables in PHP to avoid "Undefined variable" notices, always initialize variables before using them. This can be done by declaring variables with an initial value, either directly or through user input or by checking if the variable is set before using it.

// Example of properly defining and assigning values to variables
$name = "John"; // Initializing variable with a value

if(isset($age)) {
    echo "Age is set to: " . $age;
} else {
    $age = 30; // Assigning a default value if variable is not set
    echo "Age is set to default value: " . $age;
}