あなたの望む結果は一種の疑似配列文字列であるようです。これを配列またはjsonとして使用する予定がある場合は、このコードを改良して、最終的な要件に合わせることができます。
3つの異なる出発点を実証コード:(Demo)
function buildPseudoArray($month1,$year1){ // default dates in params: $month1=date('m'),$year1=date('Y') causes Fatal error
echo "Result for $month1-$year1:\n";
$m1_last=date('t',strtotime("$year1-$month1"));
if($month1==12){
$year2=$year1+1;
$month2=1;
}else{
$year2=$year1;
$month2=$month1+1;
}
$m2_last=date('t',strtotime("$year2-$month2"));
$result='';
for($i=1,$stop=31; $i<=$stop; ++$i){
$result.="['$i', ";
$result.=$i<=$m1_last ? "'$i, $month1, $year1', " : "'0, 0, 0', "; // conditionally fill missing dates
$result.=$i<=$m2_last ? "'$i, $month2, $year2'" : "'0, 0, 0'"; // conditionally fill missing dates
$result.=']'.($i<$stop ? ',' : '')."\n"; // conditionally add comma to end of row
}
return $result;
}
echo buildPseudoArray(1,2017); // shows 0, 0, 0 in first column
echo "\n---------------------\n";
echo buildPseudoArray('2',2017); // shows 0, 0, 0 in second column
echo "\n---------------------\n";
echo buildPseudoArray(12,2017); // shows incrementation into next year
出力:(Demo Link)
:
Result for 1-2017:
['1', '1, 1, 2017', '1, 2, 2017'],
['2', '2, 1, 2017', '2, 2, 2017'],
['3', '3, 1, 2017', '3, 2, 2017'],
['4', '4, 1, 2017', '4, 2, 2017'],
['5', '5, 1, 2017', '5, 2, 2017'],
['6', '6, 1, 2017', '6, 2, 2017'],
['7', '7, 1, 2017', '7, 2, 2017'],
['8', '8, 1, 2017', '8, 2, 2017'],
['9', '9, 1, 2017', '9, 2, 2017'],
['10', '10, 1, 2017', '10, 2, 2017'],
['11', '11, 1, 2017', '11, 2, 2017'],
['12', '12, 1, 2017', '12, 2, 2017'],
['13', '13, 1, 2017', '13, 2, 2017'],
['14', '14, 1, 2017', '14, 2, 2017'],
['15', '15, 1, 2017', '15, 2, 2017'],
['16', '16, 1, 2017', '16, 2, 2017'],
['17', '17, 1, 2017', '17, 2, 2017'],
['18', '18, 1, 2017', '18, 2, 2017'],
['19', '19, 1, 2017', '19, 2, 2017'],
['20', '20, 1, 2017', '20, 2, 2017'],
['21', '21, 1, 2017', '21, 2, 2017'],
['22', '22, 1, 2017', '22, 2, 2017'],
['23', '23, 1, 2017', '23, 2, 2017'],
['24', '24, 1, 2017', '24, 2, 2017'],
['25', '25, 1, 2017', '25, 2, 2017'],
['26', '26, 1, 2017', '26, 2, 2017'],
['27', '27, 1, 2017', '27, 2, 2017'],
['28', '28, 1, 2017', '28, 2, 2017'],
['29', '29, 1, 2017', '0, 0, 0'],
['30', '30, 1, 2017', '0, 0, 0'],
['31', '31, 1, 2017', '0, 0, 0']
---------------------
Result for 2-2017:
['1', '1, 2, 2017', '1, 3, 2017'],
['2', '2, 2, 2017', '2, 3, 2017'],
['3', '3, 2, 2017', '3, 3, 2017'],
['4', '4, 2, 2017', '4, 3, 2017'],
['5', '5, 2, 2017', '5, 3, 2017'],
['6', '6, 2, 2017', '6, 3, 2017'],
['7', '7, 2, 2017', '7, 3, 2017'],
['8', '8, 2, 2017', '8, 3, 2017'],
['9', '9, 2, 2017', '9, 3, 2017'],
['10', '10, 2, 2017', '10, 3, 2017'],
['11', '11, 2, 2017', '11, 3, 2017'],
['12', '12, 2, 2017', '12, 3, 2017'],
['13', '13, 2, 2017', '13, 3, 2017'],
['14', '14, 2, 2017', '14, 3, 2017'],
['15', '15, 2, 2017', '15, 3, 2017'],
['16', '16, 2, 2017', '16, 3, 2017'],
['17', '17, 2, 2017', '17, 3, 2017'],
['18', '18, 2, 2017', '18, 3, 2017'],
['19', '19, 2, 2017', '19, 3, 2017'],
['20', '20, 2, 2017', '20, 3, 2017'],
['21', '21, 2, 2017', '21, 3, 2017'],
['22', '22, 2, 2017', '22, 3, 2017'],
['23', '23, 2, 2017', '23, 3, 2017'],
['24', '24, 2, 2017', '24, 3, 2017'],
['25', '25, 2, 2017', '25, 3, 2017'],
['26', '26, 2, 2017', '26, 3, 2017'],
['27', '27, 2, 2017', '27, 3, 2017'],
['28', '28, 2, 2017', '28, 3, 2017'],
['29', '0, 0, 0', '29, 3, 2017'],
['30', '0, 0, 0', '30, 3, 2017'],
['31', '0, 0, 0', '31, 3, 2017']
---------------------
Result for 12-2017:
['1', '1, 12, 2017', '1, 1, 2018'],
['2', '2, 12, 2017', '2, 1, 2018'],
['3', '3, 12, 2017', '3, 1, 2018'],
['4', '4, 12, 2017', '4, 1, 2018'],
['5', '5, 12, 2017', '5, 1, 2018'],
['6', '6, 12, 2017', '6, 1, 2018'],
['7', '7, 12, 2017', '7, 1, 2018'],
['8', '8, 12, 2017', '8, 1, 2018'],
['9', '9, 12, 2017', '9, 1, 2018'],
['10', '10, 12, 2017', '10, 1, 2018'],
['11', '11, 12, 2017', '11, 1, 2018'],
['12', '12, 12, 2017', '12, 1, 2018'],
['13', '13, 12, 2017', '13, 1, 2018'],
['14', '14, 12, 2017', '14, 1, 2018'],
['15', '15, 12, 2017', '15, 1, 2018'],
['16', '16, 12, 2017', '16, 1, 2018'],
['17', '17, 12, 2017', '17, 1, 2018'],
['18', '18, 12, 2017', '18, 1, 2018'],
['19', '19, 12, 2017', '19, 1, 2018'],
['20', '20, 12, 2017', '20, 1, 2018'],
['21', '21, 12, 2017', '21, 1, 2018'],
['22', '22, 12, 2017', '22, 1, 2018'],
['23', '23, 12, 2017', '23, 1, 2018'],
['24', '24, 12, 2017', '24, 1, 2018'],
['25', '25, 12, 2017', '25, 1, 2018'],
['26', '26, 12, 2017', '26, 1, 2018'],
['27', '27, 12, 2017', '27, 1, 2018'],
['28', '28, 12, 2017', '28, 1, 2018'],
['29', '29, 12, 2017', '29, 1, 2018'],
['30', '30, 12, 2017', '30, 1, 2018'],
['31', '31, 12, 2017', '31, 1, 2018']
これはあなたのGoogleのチャートタスクの準備をコードであります 回の通話の
出力:
Result for 1-2017:
[['Day', 'Jan 2017', 'Feb 2017'],
['01.', '22', '9', ],
['02.', '30', '24', ],
['03.', '26', '5', ],
['04.', '46', '25', ],
['05.', '7', '24', ],
['06.', '17', '22', ],
['07.', '34', '27', ],
['08.', '0', '26', ],
['09.', '43', '38', ],
['10.', '27', '49', ],
['11.', '7', '22', ],
['12.', '14', '26', ],
['13.', '0', '30', ],
['14.', '45', '43', ],
['15.', '30', '45', ],
['16.', '34', '34', ],
['17.', '19', '30', ],
['18.', '34', '40', ],
['19.', '25', '39', ],
['20.', '1', '1', ],
['21.', '40', '49', ],
['22.', '26', '40', ],
['23.', '37', '44', ],
['24.', '16', '8', ],
['25.', '21', '3', ],
['26.', '47', '35', ],
['27.', '47', '25', ],
['28.', '1', '43', ],
['29.', '7', '30', ],
['30.', '8', '28', ],
['31.', '38', '13', ]]
---------------------
Result for 2-2017:
[['Day', 'Feb 2017', 'Mar 2017'],
['01.', '5', '48', ],
['02.', '43', '33', ],
['03.', '32', '13', ],
['04.', '30', '23', ],
['05.', '10', '41', ],
['06.', '3', '16', ],
['07.', '46', '23', ],
['08.', '3', '12', ],
['09.', '6', '23', ],
['10.', '48', '29', ],
['11.', '6', '49', ],
['12.', '14', '34', ],
['13.', '44', '2', ],
['14.', '17', '11', ],
['15.', '47', '44', ],
['16.', '35', '9', ],
['17.', '0', '26', ],
['18.', '26', '0', ],
['19.', '7', '5', ],
['20.', '0', '17', ],
['21.', '4', '9', ],
['22.', '43', '37', ],
['23.', '21', '28', ],
['24.', '22', '12', ],
['25.', '15', '50', ],
['26.', '16', '34', ],
['27.', '33', '21', ],
['28.', '2', '37', ],
['29.', '31', '41', ],
['30.', '50', '28', ],
['31.', '3', '34', ]]
---------------------
Result for 12-2017:
[['Day', 'Dec 2017', 'Jan 2018'],
['01.', '42', '48', ],
['02.', '17', '44', ],
['03.', '11', '26', ],
['04.', '5', '11', ],
['05.', '44', '1', ],
['06.', '37', '33', ],
['07.', '33', '32', ],
['08.', '43', '35', ],
['09.', '5', '35', ],
['10.', '27', '6', ],
['11.', '24', '0', ],
['12.', '35', '33', ],
['13.', '38', '4', ],
['14.', '11', '35', ],
['15.', '0', '18', ],
['16.', '3', '43', ],
['17.', '31', '20', ],
['18.', '12', '19', ],
['19.', '38', '34', ],
['20.', '38', '45', ],
['21.', '11', '32', ],
['22.', '12', '13', ],
['23.', '47', '38', ],
['24.', '37', '17', ],
['25.', '36', '44', ],
['26.', '47', '4', ],
['27.', '40', '48', ],
['28.', '5', '20', ],
['29.', '18', '4', ],
['30.', '15', '48', ],
['31.', '38', '19', ]]
なぜあなたの日付は、そのようにフォーマットされていますか? – Kisaragi
私はカスタム関数 'getOrdersByDay($ day_number、$ month_number、$ year_number)'で、日、月、年をパラメータとして使用する必要があるためです。すでにコンマでフォーマットされた配列の日付を持つ方が簡単です。 – Kheber
年を最初に使用して日付を処理します。自分自身をISO8601で考えてみてください。特定の出力フォーマットが必要な場合は、出力を生成するときに書式設定でそれを処理してください。データ構造は出力フォーマットによって管理されるべきではありません。 – ghoti