What are some key differences between the logic and function sections in PHP scripts, and how should they be properly structured for optimal performance?

When writing PHP scripts, it is important to separate the logic (such as conditional statements and loops) from the function definitions. This separation helps in maintaining a clean and organized codebase. To properly structure the script for optimal performance, make sure to place the logic section above the function section and avoid mixing them together.

// Logic section
$userAge = 30;

if ($userAge >= 18) {
    echo "You are an adult.";
} else {
    echo "You are a minor.";
}

// Function section
function calculateSum($num1, $num2) {
    return $num1 + $num2;
}

$result = calculateSum(5, 10);
echo $result;