亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

需要在此循環中將常量更改為動態

需要在此循環中將常量更改為動態

PHP
搖曳的薔薇 2023-09-22 16:31:40
我正在運行制造計劃(使用 PHP 代碼),但目前它是靜態的(意味著我無法添加假期或無法更改制造能力 - 當前制造能力是靜態的每天 1700 平方英尺)請看下面的代碼$max = 1700;$dailyLeft = $max;$current = reset($priorityArraySum);$output = [];//$day = date('Y-m-d');$day = date('Y-m-d');while (true)    {  // echo $current."/".$dailyLeft."=".$day.PHP_EOL;  if ( $current >= $dailyLeft )   {    //$day=date('Y-m-d', strtotime($day. ' + 1 days'));    $output[] = ["priority" => key($priorityArraySum), "amount" => $dailyLeft, "day" => $day];    $day=date('Y-m-d', strtotime($day. ' + 1 days'));    $current -= $dailyLeft;    $dailyLeft = $max;  } else {    $output[] = ["priority" => key($priorityArraySum), "amount" => $current, "day" => $day];    $dailyLeft -= $current;    if ( ($current = next($priorityArraySum)) === false ) {      break;    }  }}echo '<pre/>';print_r($output);echo '<pre/>';exit;使用上面的代碼,我可以安排我的制造計劃,見下圖當前日程圖像當前代碼的問題是,我們每天有 1700 個靜態容量,我們希望有動態容量,例如第一天 1700 個,第二天 1900 個,節假日 0 個。我們如何更改此代碼以使其動態化?目前我正在嘗試下面的代碼,但它不起作用
查看完整描述

1 回答

?
白豬掌柜的

TA貢獻1893條經驗 獲得超10個贊

這是基于您顯示的第二個代碼。if()一個問題是,您總是將這一天推遲,并且您應該只在當天容量已滿的第一部分執行此操作。


為了方便起見,我還在循環中預先檢索了所有日期和容量,并將它們存儲在以日期為鍵的數組中。


$today=date('Y-m-d');

$pln_qry=mysql_query("select * 

    from tbl_mfg_schedule 

    where ms_date > '".$today."' 

    order by ms_date") or die(mysql_error());

// Load list of days and production

$plnList = [];

while ( $pln_data=mysql_fetch_array($pln_qry) ) {

    $plnList [ $pln_data['ms_date'] ] = $pln_data['ms_po_sqft'];

}



$current = reset($priorityArraySum);

$output = [];

$day = date('Y-m-d');

// Set max from production plan

$max = $plnList[ $day ];

//$max = 1700;

$dailyLeft = $max;

while (true)    {

    //echo $dailyLeft."</br>";

    

    if ( $current >= $dailyLeft )   {

        //$day=date('Y-m-d', strtotime($day. ' + 1 days'));

        $output[] = ["priority" => key($priorityArraySum),

                "amount" => $dailyLeft,

                "day" => $day

        ];

        $day=date('Y-m-d', strtotime($day. ' + 1 days'));

        $current -= $dailyLeft;

        

        // Move onto the next days capacity, if no specific value assume

        // same as last ( ?? $max)

        $max = $plnList[ $day ] ?? $max;

        $dailyLeft = $max;

        

    }

    else    {

        $output[] = ["priority" => key($priorityArraySum),

                "amount" => $current,

                "day" => $day

        ];

        $dailyLeft -= $current;

        if ( ($current = next($priorityArraySum)) === false )   {

            break;

        }

    }

    

}

echo '<pre/>';

print_r($output);

echo '<pre/>';

使用一些虛擬測試數據(請注意,缺少日期,因此假設它將與...2020-08-14相同2020-08-13


$priorityArraySum = [2000, 200, 6000, 1200];


$plnList = [ '2020-08-10' => 1700,

        '2020-08-11' => 1700,

        '2020-08-12' => 0,

        '2020-08-13' => 500,

        '2020-08-15' => 1700];

它產生...


<pre/>Array

(

    [0] => Array

        (

            [priority] => 0

            [amount] => 1700

            [day] => 2020-08-10

        )


    [1] => Array

        (

            [priority] => 0

            [amount] => 300

            [day] => 2020-08-11

        )


    [2] => Array

        (

            [priority] => 1

            [amount] => 200

            [day] => 2020-08-11

        )


    [3] => Array

        (

            [priority] => 2

            [amount] => 1200

            [day] => 2020-08-11

        )


    [4] => Array

        (

            [priority] => 2

            [amount] => 0

            [day] => 2020-08-12

        )


    [5] => Array

        (

            [priority] => 2

            [amount] => 500

            [day] => 2020-08-13

        )


    [6] => Array

        (

            [priority] => 2

            [amount] => 500

            [day] => 2020-08-14

        )


    [7] => Array

        (

            [priority] => 2

            [amount] => 1700

            [day] => 2020-08-15

        )


    [8] => Array

        (

            [priority] => 2

            [amount] => 1700

            [day] => 2020-08-16

        )


    [9] => Array

        (

            [priority] => 2

            [amount] => 400

            [day] => 2020-08-17

        )


    [10] => Array

        (

            [priority] => 3

            [amount] => 1200

            [day] => 2020-08-17

        )


)


查看完整回答
反對 回復 2023-09-22
  • 1 回答
  • 0 關注
  • 117 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號