我試圖寫程序的計算接下來20日期指定開始日期後,再從20日我有不包括週末& Holidays(Array holidays('2016-12-13',2016-12-24))
和傳球假日array(Eg:- holidays('2016-12-13',2016-12-24)))
後結果數組只包括工作日不包括星期六&週日,從這個結果數組,它必須從結果數組中排除。 I:E;如何從數組中刪除重複的元素後與PHP中的另一個數組合並?
我想預期的輸出下面提到
。Array ([2016-12-01] => [2016-12-02] => [2016-12-05] => [2016-12-06] => [2016-12-07] => [2016-12-08] => [2016-12-09] => [2016-12-12] => [2016-12-13] => [2016-12-14] => [2016-12-15] => [2016-12-16] => [2016-12-19] => [2016-12-20] => [2016-12-21] => [2016-12-22] => [2016-12-23] => [0] => 2016-12-13 [1] => 2016-12-24)
>但我想預期的輸出: - - :
<?php
$Date=array('2016-12-01');
echo "\n <br />Start Date:-" . $Date[0] . "";
/*Code For Generating Next 20 Dates Starts*/
//$start = strtotime($s_row['schedule_start_date']);
$start = strtotime('2016-12-01');
$dates=array();
for($i = 0; $i<20; $i++)
{
array_push($dates,date('Y-m-d', strtotime("+$i day", $start)));
}
echo "\n <br /> Array Of next 20 Days/dates of Given:-";
print_r($dates);
$start=array();
$start=$dates; /*Code For Generating Next 20 Dates Ends*/
$result=array();
$start = strtotime(array_values($Date)[0]);
//$end = strtotime(array_values($Date)[30]);
$result = array();
$begin = new DateTime('2016-12-01');
$end = new DateTime('');
//$end = $end->modify('+1 day');
$interval = new DateInterval('P1D');
$daterange = new DatePeriod($begin, $interval ,$end);
foreach($daterange as $date)
{
//echo $date->format("Y-m-d") . "<br>";
if (date('N', $start) <= 5) /* 'N' number days 1 (mon) to 7 (sun) */
/*5 weekday */
{
$current = date('Y-m-d', $start); //m/d/Y
$result[$current] = '';
}
$start += 86400;
//echo "Days Without Sat Sun".$result[date($date->format("Y-m-d"))];
//echo "Days Without Sat Sun".$result2[date($current->format("Y-m-d"))];
}
echo " \n <br /> Dates Without Weekends LIKE (Excluding Saturday & Sunday):-";
print_r($result);
/*For Holiday*/
$FinalArray = array();
$holidays = array(
'2016-12-13',
'2016-12-24',
);
echo " \n <br /> Given Holiday Dates Are:-";
print_r($holidays);
$a1 = $result;
$a2 = $holidays;
$array = array_diff(array_merge($a1,$a2),array_intersect($a1,$a2));
echo "\n <br /> Output:-";
print_r($array);
?>
,因爲它使輸出
Array ([2016-12-01] => [2016-12-02] => [2016-12-05] => [2016-12-06] => [2016-12-07] => [2016-12-08] => [2016-12-09] => [2016-12-12] => [2016-12-14] => [2016-12-15] => [2016-12-16] => [2016-12-19] => [2016-12-20] => [2016-12-21] => [2016-12-22] => [2016-12-23]
你可以看到,2016-12-13
是不存在以上的預期輸出爲在'2016-12-13',2016-12-24通過節假日數組($holidays = array('2016-12-13', '2016-12-24',);)
i:e;如果我通過任何節假日排列數組它不應該包含在結果Array(). i:e 2016-12-13
是可用的結果數組以及假日數組所以雖然打印最終輸出: -13th date(2016-12-13)
不應包含在最終輸出。任何人解決這個問題都將被提前感謝。
儘管使用內置的PHP數組函數,解決方案以任何其他方式使用foreach循環或任何函數將讚賞 –
array_unique()函數可以幫助你 – Gulshan