I am building a calendar application which will allow our admin team to input staff holidays, training days, sick days etc and all staff to view who is in/out on any given day. The calendar is built as is the mechanism to record days off. I’m struggling to display who is off when. Using print_r I get the following back from the server, showing name, date and reason for absence:
Array (
[0] => stdClass Object ( [name] => Becca [date] => 2012-10-10 [reason] => Sick )
[1] => stdClass Object ( [name] => Frank [date] => 2012-09-12 [reason] => Sic )
[2] => stdClass Object ( [name] => Frank [date] => 2012-10-14 [reason] => Sic )
[3] => stdClass Object ( [name] => Paola [date] => 2012-10-10 [reason] => Sic )
[4] => stdClass Object ( [name] => Clive [date] => 2012-10-14 [reason] => Hol ) )
I can iterate through and display some of the names and dates, but if more than one person is off on a given date (eg Becca, Paola), only the last name is displayed, I believe because the key must be unique. The following code does this, where ‘date(“Y-m-d”, $date)’ is the means of printing the dates on the calendar :
foreach ($absenceArray as $dateofabsence=>$name){
if (date("Y-m-d", $date) == $dateofabsence){
$showname[$x] = $name;
}
}
Can someone please demonstrate how I can iterate through the above array and link each name to a corresponding date in my calendar.
I apologise that I no doubt have not explained myself properly but my brain is frazzled.
When iterating through this array, the key will be numeric and the ‘value’ will be an object, as you can see in the print_r dump. So the way to go will be like: