I have been trying to read the errors and figure out the solution for a while now, I can't seem to get it.
In short, the code below grabs a numbered list of php files that displays the events. However, when there are no php files in this directory, it displays the text, Sorry, No upcoming events.
$events = glob("$_SERVER[DOCUMENT_ROOT]/assets/events/shot/*.php");
if(count($events)) {
natcasesort($events);
$i=0;
foreach($events as $event) {
if($i > 3) {
break;
}
$event = basename($event);
include("$_SERVER[DOCUMENT_ROOT]/assets/events/shot/$event");
$i++;
};
}
else {
echo 'Sorry, no upcoming events.';
}
My problem is, when there are no php files in the directory, I get the errors:
Warning: natcasesort() expects parameter 1 to be array, boolean given in /home/famili23/public_html/assets/events/shot.php on line 11
Warning: Invalid argument supplied for foreach() in /home/famili23/public_html/assets/events/shot.php on line 14
I cannot quite figure this one out. If someone can help me on this, thank you!!