<?php
// 輸入一個日期,用程式計算出當天是當年度的第幾天?
$m = 2;
$d = 3;
$sYear = array (
"1" => "31",
"2" => "28",
"3" => "31",
"4" => "30",
"5" => "31",
"6" => "30",
"7" => "31",
"8" => "31",
"9" => "30",
"10" => "31",
"11" => "30",
"12" => "31"
);
// 區分 月/日
// ans = 月 array[x-1]之前的總和 + 日
if($m==1)echo $x = $d+ $sYear["0"];
if($m==2)echo $x = $d+ $sYear["0"]+$sYear["1"];
if($m==3)echo $x = $d+ $sYear["0"]+$sYear["1"]+$sYear["2"];
if($m==3)echo $x = $d+ $sYear["0"]+$sYear["1"]+$sYear["2"]+$sYear["3"];
// for ($i=1;$i<$m ;$i++)
// {$x = $d + $sYear[$m-1]; echo $x; }
// var_dump ( $sYear );
?>
請問我該如何把下面那個if 設成迴圈 每次可以多加一個$year[""];
我設的方法他都只會重複$m-1的月份幾次 而不是遞加前面的
感謝