In the provided PHP code snippet, how can the variables for school, work, and hobbies be properly initialized to avoid the "Notice: Undefined variable" error on lines 851, 855, and 866?

The "Notice: Undefined variable" error occurs because the variables for school, work, and hobbies are being accessed before they are initialized. To avoid this error, you can initialize these variables with empty values before using them in the code snippet.

<?php
// Initialize variables to avoid "Undefined variable" error
$school = "";
$work = "";
$hobbies = "";

if ($student) {
    $school = "ABC School";
}

if ($employee) {
    $work = "XYZ Company";
}

if ($person) {
    $hobbies = "Reading, Painting";
}

echo "School: " . $school . "<br>";
echo "Work: " . $work . "<br>";
echo "Hobbies: " . $hobbies . "<br>";
?>