|
 |
|
ขอความช่วยเหลือ code ตัวอย่าง php เกี่ยวกับการเฉลี่ยสินค้าใส่รถบรรทุกให้เต็มคันก่อน |
|
 |
|
|
 |
 |
|
กำหนดตัวแปรที่จำเป็นต้องใช้ เช่น products, maxWeight, trucks, currentTruck, etc.
แล้วเข้า loop เพื่อจัดสินค้าทีละชิ้น โดยเช็คน้ำหนักคงเหลือของสินค้าเทียบกับ maxWeight ไปเรื่อยๆ
สุดท้ายเก็บผลลัพธ์ใน array เพื่อแสดงผลต่อไป
อะ ขึ้นโครงให้ เว้นแค่ลอจิกและคำนวณส่วนที่เหลือ
Code (PHP)
$products = [
'Product A' => 500,
'Product B' => 500,
'Product C' => 1500,
'Product D' => 2000,
'Product E' => 2000,
'Product F' => 1500,
];
$maxWeightPerTruck = 3000;
$trucks = [];
$currentTruck = 1;
foreach ($products as $productName => $productWeight) {
while ($productWeight > 0) {
//...
$productWeight -= $availableSpace;
$currentTruck++;
}
}
print_r($trucks);
ตัวอย่างผลลัพธ์ของ $trucks ที่ควรได้หลังเข้า loop
Array
(
[truck 1] => Array
(
[0] => Array
(
[product_name] => Product A
[filled_weight] => 500
)
[1] => Array
(
[product_name] => Product B
[filled_weight] => 500
)
[2] => Array
(
[product_name] => Product C
[filled_weight] => 1500
)
[3] => Array
(
[product_name] => Product D
[filled_weight] => 500
)
)
[truck 2] => Array
(
[0] => Array
(
[product_name] => Product D
[filled_weight] => 1500
)
[1] => Array
(
[product_name] => Product E
[filled_weight] => 1500
)
)
[truck 3] => Array
(
[0] => Array
(
[product_name] => Product E
[filled_weight] => 500
)
[1] => Array
(
[product_name] => Product F
[filled_weight] => 1500
)
)
)
นี่คือแนวทางสำหรับนำไปต่อยอดเอง (ความรู้มาก่อน)
ถ้าอยากได้แบบเสร็จเลย จ้างเอาครับ (เอางานมาก่อน)
|
 |
 |
 |
 |
Date :
2023-08-08 13:17:35 |
By :
009 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณครับ
|
 |
 |
 |
 |
Date :
2023-08-08 15:59:45 |
By :
Newuser99 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 04
|