How can PHP scripts be structured using functions or classes to improve code organization and reusability?

To improve code organization and reusability in PHP scripts, functions or classes can be used. Functions can encapsulate specific blocks of code that perform a particular task, making the code more modular and easier to maintain. Classes can group related functions and variables together, allowing for better organization and encapsulation of code.

// Example using functions for code organization and reusability

function calculateArea($radius) {
    return pi() * $radius * $radius;
}

function calculateVolume($radius, $height) {
    return calculateArea($radius) * $height;
}

$radius = 5;
$height = 10;

$area = calculateArea($radius);
$volume = calculateVolume($radius, $height);

echo "Area: " . $area . "<br>";
echo "Volume: " . $volume;