Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/226.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php部门剩余和;阵列_Php_Arrays_Function_Division - Fatal编程技术网

Php部门剩余和;阵列

Php部门剩余和;阵列,php,arrays,function,division,Php,Arrays,Function,Division,我有一个数组 $blocks 它有4个具有常量值的项 A、 B、C、D $blocks["a"] = 20; $blocks["b"] = 1000; $blocks["c"] = 10000; $blocks["d"] = 50000; 另一个函数返回一个值,比如358020 (通常很高,但可以降到几十 我该如何编写一个函数来获取这个值并返回一个数组,该数组包含每个项存在的数量 输出示例如下: $output["a"] = 1; $output["b"] = 3; $output["c

我有一个数组 $blocks 它有4个具有常量值的项 A、 B、C、D

$blocks["a"] = 20;
$blocks["b"] = 1000;
$blocks["c"] = 10000;
$blocks["d"] = 50000;
另一个函数返回一个值,比如358020 (通常很高,但可以降到几十

我该如何编写一个函数来获取这个值并返回一个数组,该数组包含每个项存在的数量

输出示例如下:

 $output["a"] = 1;
 $output["b"] = 3;
 $output["c"] = 0;
 $output["d"] = 7;
从最大的块开始,该块中有多少适合该值,然后将剩余部分传递给下一个最大的块,依此类推…

CalculateEnumberCredits(25000);
calculateNumberCredits(25000);

function calculateNumberCredits($experience) {

    # The credits we have
    $credits = array(
        'a' => '10000',
        'b' => '2000',
        'c' => '1000',
    );

    # Keep track of the amount needed per credit
    $timesCreditNeeded = array();

    # Start calculating the amount per credit we need
    foreach($credits as $creditID => $creditAmount) {

        # 1) Calculate the number of times the amount fits within the amount of experience
        $times = floor($experience / $creditAmount);

        # 2) Calculate the remainder of the above division en cache is for the next     calculation
        $experience = $experience % $creditAmount;

        # 3) Cache the number of times the credit fits within the experience
        $timesCreditNeeded[$creditID] = $times;

    }

    echo '<pre>';
    print_r($timesCreditNeeded);

    return $timesCreditNeeded;

}

// Will return Array ( [a] => 2 [b] => 2 [c] => 1 )
功能积分($experience){ #我们的学分 $credits=数组( “a”=>“10000”, “b”=>“2000”, “c”=>“1000”, ); #跟踪每笔信贷所需的金额 $TimesCreditRequired=array(); #开始计算我们需要的每笔信用额度 foreach($creditID=>$creditAmount时的贷项){ #1)计算该量与经验量相符的次数 $times=下限($experience/$creditAmount); #2)计算上述除法en缓存的剩余部分,以便下一次计算 $experience=$experience%$creditAmount; #3)缓存信用卡符合体验的次数 $TimesCreditRequired[$creditID]=$times; } 回声'; 打印(所需时间); 返回所需的$TimesCredit; } //将返回数组([a]=>2[b]=>2[c]=>1)
我循环检查你系统中的学分。在本例中,信用从高到低依次排列。如果情况并非如此,则应订购以获得所需的结果

1)对于每个信用卡,我都会尝试找出信用卡符合特定用户体验的最大次数。因为floatnumber没有任何意义,我们需要除法的结果

2)在我找到积分拟合的次数后,我计算下一次迭代的余数(下一个积分)。你可以通过计算余数找到余数

3)最后但并非最不重要的一点是,我缓存了信用卡符合的次数


希望这有帮助

什么是358020?这与什么相对应?这个数字是一个函数的结果,该函数计算游戏中不同级别之间的训练点数,即经验点数。问题是帮助用户了解他们需要多少“应用内购买”才能提前购买。