How can PHP logic be used to efficiently handle price allocation for packages based on weight ranges?

To efficiently handle price allocation for packages based on weight ranges in PHP, you can use conditional statements to determine which price tier the package falls into based on its weight. By setting up a series of if-else statements or a switch case, you can easily assign the appropriate price to the package based on its weight range.

$weight = 10; // weight of the package in kg

if ($weight <= 5) {
    $price = 10; // price for packages weighing up to 5kg
} elseif ($weight <= 10) {
    $price = 15; // price for packages weighing between 5kg and 10kg
} elseif ($weight <= 15) {
    $price = 20; // price for packages weighing between 10kg and 15kg
} else {
    $price = 25; // price for packages weighing more than 15kg
}

echo "The price for a package weighing $weight kg is $price.";