私はこの配列を持っている:月のマルチ配列検索でループしない方法と月の名前を挿入するには?
$rows = array_map(function($item) {
return (object) ['c' => [
(object) ['v' => $item->month, 'f' => null],
(object) ['v' => intval($item->jobcount), 'f' => null],
(object) ['v' => intval($item->interncount), 'f' => null]
]];
}, array_values($data));
この配列は、データベースから毎月のデータを数えます。
ただし、データが入っている月のみをリストします。データがないのに1月から12月までの別の月を表示したい。
$months = array('January', 'February', 'March', 'April', 'May', 'Jun', 'July', 'August', 'September', 'October', 'November', 'December');
どのように私は$行の配列にループしたいと配列には月がない場合見つけ、それは$ヶ月から月の名前を挿入します:
は、だから私は、数ヶ月のダミー配列を作成します内部に0の値がありますか?私のサンプルデータ:
Array ([0] => stdClass Object ([c] => Array (
[0] => stdClass Object ([v] => July [f] =>) [1] => stdClass Object ([v] => 6 [f] =>) [2] => stdClass Object ([v] => 2 [f] =>))) [1] => stdClass Object ([c] => Array (
[0] => stdClass Object ([v] => August [f] =>) [1] => stdClass Object ([v] => 0 [f] =>) [2] => stdClass Object ([v] => 3 [f] =>))))
予想される出力:
Array ([0] => stdClass Object ([c] => Array (
[0] => stdClass Object ([v] => January [f] =>) [1] => stdClass Object ([v] => 0 [f] =>) [2] => stdClass Object ([v] => 0 [f] =>))) [1] => stdClass Object ([c] => Array (
[0] => stdClass Object ([v] => February [f] =>) [1] => stdClass Object ([v] => 0 [f] =>) [2] => stdClass Object ([v] => 0 [f] =>))) [1] => stdClass Object ([c] => Array (
[0] => stdClass Object ([v] => March [f] =>) [1] => stdClass Object ([v] => 0 [f] =>) [2] => stdClass Object ([v] => 0 [f] =>))) [1] => stdClass Object ([c] => Array (
[0] => stdClass Object ([v] => April [f] =>) [1] => stdClass Object ([v] => 0 [f] =>) [2] => stdClass Object ([v] => 0 [f] =>))) [1] => stdClass Object ([c] => Array (
[0] => stdClass Object ([v] => Mei [f] =>) [1] => stdClass Object ([v] => 0 [f] =>) [2] => stdClass Object ([v] => 0 [f] =>))) [1] => stdClass Object ([c] => Array (
[0] => stdClass Object ([v] => Jun [f] =>) [1] => stdClass Object ([v] => 0 [f] =>) [2] => stdClass Object ([v] => 0 [f] =>))) [1] => stdClass Object ([c] => Array (
[0] => stdClass Object ([v] => July [f] =>) [1] => stdClass Object ([v] => 6 [f] =>) [2] => stdClass Object ([v] => 2 [f] =>))) [1] => stdClass Object ([c] => Array (
[0] => stdClass Object ([v] => August [f] =>) [1] => stdClass Object ([v] => 0 [f] =>) [2] => stdClass Object ([v] => 3 [f] =>))) [1] => stdClass Object ([c] => Array (
[0] => stdClass Object ([v] => September [f] =>) [1] => stdClass Object ([v] => 0 [f] =>) [2] => stdClass Object ([v] => 0 [f] =>))) [1] => stdClass Object ([c] => Array (
[0] => stdClass Object ([v] => October [f] =>) [1] => stdClass Object ([v] => 0 [f] =>) [2] => stdClass Object ([v] => 0 [f] =>))) [1] => stdClass Object ([c] => Array (
[0] => stdClass Object ([v] => November [f] =>) [1] => stdClass Object ([v] => 0 [f] =>) [2] => stdClass Object ([v] => 0 [f] =>))) [1] => stdClass Object ([c] => Array (
[0] => stdClass Object ([v] => December [f] =>) [1] => stdClass Object ([v] => 0 [f] =>) [2] => stdClass Object ([v] => 0 [f] =>))))
あなたのサンプルデータと予想される出力 –