我試圖做一個有趣的小PHP腳本,我有點卡住了。
我想劃分一個整數(例如5
)在多個值。
例如:如何在PHP中將整數分成多個值?
$total = 5;
$mike = 0;
$ralf = 0;
$ashley = 0;
// Run the magic here
echo "Mike has " . $mike . " apples, Ralf has " . $ralf ." apples and Ashley has " . $ashley . " apples";
,我希望會是這個樣子的輸出:
Mike has 2 apples, Ralf has 1 apples and Ashley has 2 apples
有沒有辦法如何做到這一點? :)
我不能這樣做硬編碼,因爲我想要的值是隨機的。
乾杯
是這樣的:http://stackoverflow.com/questions/7289136/how-to-make-5-random-numbers-with-sum-of-100 – ashanrupasinghe
的可能的複製[如何使5隨機數與總和100](http://stackoverflow.com/questions/7289136/how-to-make-5-random-numbers-with-sum-of-100) –
你想要隨機整除整數,每個人都假設到目前爲止,或儘可能平等? –