I want to check for month in one year found in $month variable, if data found show the month (in number), if not found show '0'
<?php
$month = array(
'2',
'3',
'4',
'7',
'12'
);
for ($i = 1; $i <= 12; $i++) {
foreach($month as $key => $value) {
if ($value == $i) {
echo "$i" . "
";
}
else {
echo "0" . "
";
}
}
}
from code above I get
0
0
0
0
0
2
0
0
0
0
0
3
0
0
0
0
0
4
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
7
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
12
if I add break 1 after else
for ($i = 1; $i <= 12; $i++) {
foreach($month as $key => $value) {
if ($value == $i) {
echo "$i" . "
";
}
else {
echo "0" . "
";
}
break 1;
}
}
I got 12 result but not what I expected.
0
2
0
0
0
0
0
0
0
0
0
0
what I want is
0
2
3
4
0
0
7
0
0
0
0
12
If I able to get that result I want to put that these result in graph using chartjs, I know how to do that. I only want to know how to get these result, any help appriciate