预算选项计算器

Budgeting Option Calculator

我想知道如何才能为可能发生以下情况的潜在客户组装预算计算器。

这个问题的原因是分配给每项服务的预算百分比应根据 'big picture' 而变化,但最终总数应始终等于 100%。

我想有很多可能的组合结果。 ...我在看一个项目的怪物吗?这可以在 PHP 中完成吗?

通过适当的计划,这是可能的。如果您遵循 SDLC,即使它只是您,您也不应该有任何问题

您需要在问题中添加更多详细信息以获得更具体的答案,但数学非常简单。

如果您对每项服务应用权重,则计算所有选定服务的权重总和,除以创建百分比并使用该百分比计算总支出:

$budget = 10000;
//service name => weight
$selectedServices = [
    'one'=>6,
    'two'=>3,
    'three'=>9,
    'four'=>2
];

$totalWeights= array_sum($selectedServices);

foreach($selectedServices as $key => $item){
    $percent = $item / ($totalWeights /100);
    $cost = $budget * ($percent/100);
    echo sprintf("<p>Service %s will cost %s of your budget (£%s)</p>", $key, $percent, $cost);
}