I am working on using in_array() to check if a Course object called (appropriately named) Course is in an array.
One issue I am having is, I want to use a specific property within my Course object to do the object comparison, instead of comparison of the entire object.
Specifically, I want to use the $course->getShortName() to do the comparison. Why? Because all the other private variables within my Course object can be different, except for the short_name property which can stay the same, and that's why I want to use it to do the object property.
Method that does the comparison:
public function overlap($courses, $course_temp) {
for ($i = 0; $i < count($courses); $i = $i + 1) {
if ($this->overlapCourses($courses[$i], $course_temp)) {
// Push the class that is conflicted to the conflictedClass
// array
// TODO: Figure out why it's being added to the list
if(!in_array($courses[$i], $this->conflictClasses)) {
array_push($this->conflictClasses, $courses[$i]);
}
// Push the class that is conflicted with to the
// conflictedClass array
// TODO: Figure out why it's being added to the list
if(!in_array($course_temp, $this->conflictClasses)) {
array_push($this->conflictClasses, $course_temp);
}
return false;
}
}
return false;
}
Getter from my Course class
public function getShortName(){
return $this->short_name;
}
tl;dr: Instead of compare object, compare one property of the object