I am a junior programmer who is still learning to write code. I have this array in PHP
$days = array();
for($date = $from_date; $date <= $to_date; $date->modify('+1 day')) {
array_push($days,strtolower($date->format('l')));
}
From this array there will be a list for the days selected by the user (Monday, Tuesday, etc.)
Then I have this table in my database
work_scheme
Work_scheme consists of a table
//field_name => data
Monday => Working Day
Tuesday => Working Day
Wednesday => Working Day
Thursday => Working Day
Friday => Working Day
Saturday => Half Day
Sunday => Off Day
this is my work_days array that is retrieved from the database
$working_days = array();
if(count($work_scheme) > 0){
foreach($work_scheme as $r){
$working_days[0] = array(
"monday" => $r['monday']
);
$working_days[1] = array(
"tuesday" => $r['tuesday']
);
$working_days[2] = array(
"wednesday" => $r['wednesday']
);
$working_days[3] = array(
"thursday" => $r['thursday']
);
$working_days[4] = array(
"friday" => $r['friday']
);
$working_days[5] = array(
"saturday" => $r['saturday']
);
$working_days[6] = array(
"sunday" => $r['sunday']
);
}
}
So, how can I compare the array obtained from user activity to my table in the database?
I have the following code but it does not work properly
for($i = 0; $i < count($days); $i++){
for($x = 0; $x < count($working_days); $x++){
$total_days = 0;
if($days[$i] == $working_days[$x]){
echo "hello world";
}
}
}
I notice that $ working_days [$ x] will not return the day name to me, instead it will return me the working day, half day or day. How can I compare the day name from $ days () to $ work_days?
, - , , , 1,5 ?
Working day = 1
Half day = 0.5
Off day = 0