you have referenced the variable as an array first time. but when you are using it for array push with $activeCourses = it becomes an integer field as array_push returns an integer value and then when it comes to next array push in the next iteration, your activeCourses variable is no longer an array. so use like
$activeCourses = array();
foreach ($allCourses as $course) {
if (strtotime($course->end_date) > time()) {
array_push($activeCourses, $course);
}
}
or
$activeCourses = array();
foreach ($allCourses as $course) {
if (strtotime($course->end_date) > time()) {
$activeCourses[] = $course;
}
}
$activeCourses = array_push($activeCourses, $course);will change the value of$activeCoursesto an integer (specifically the number of elements in the array). You just needarray_push($activeCourses, $course);to alter the array, or more simply$activeCourses[] = $course;.