Hi! Could we please enable some services and cookies to improve your experience and our website?
Online Sandbox for SQL and PHP: Write, Run, Test, and Share SQL Queries and PHP Code
<?php
$amount = 27;
$wareh = 4
$wareh_id = [
'3' => 3,
'2' => 2,
'1' => 1,
'0' => 0
];
arsort($wareh_id);
$i= 0;
$arr=[];
foreach($wareh_id as $key=>$value){
$arr[$key] = floor($amount / ($wareh - $i));
$i++;
}
$arr[$key] += $num - array_sum($arr);