I think a neater way to do it in PHP would be to declare an associative array of weights, this separates the data from the algorithm:
$weight=array(
1=>1,
3=>3,
4=>10
);
$result = mysql_query("SELECT `number` FROM `packages`");
$sum=0;
while ($row = mysql_fetch_assoc($result))
{
$n = $row['number'];
if (isset($weight[$n]))
{
$sum+=$weight[$n];
}
else
{
#handle error somehow, maybe with a default weight
die("Unexpected value $n");
}
}
An better alternative would be to make this entirely data driven and put your weights in a table
#create and populate the weights table
create table weight (number int, weight int, primary key(number));
insert into weight (number,weight) values (1,1),(3,3),(4,10);
#figure out total weight
select sum(weight) from package inner join weight using(number);
With weights in the database, you could provide a UI to alloww users of your application to adjust the weights.