In the code below, I create an object instance $T, give its properties values, and add it to my array of objects called $teacherObjArray. However, where I'm having trouble is if the object instance already exists (this is checked by the teacherExists() function)... how does does the program know which $T object I am accessing? In other words, How can I program it to where it UPDATES the CORRECT within the array of objects? My definition of correct is where $teacherName is the same as object property LName. I appreciate the help :)
function teacherExists($teacherObjArray, $teacherName) {
foreach ($teacherObjArray as $Teacher) {
if ($Teacher->LName == $teacherName) return true; //can i return index here?
}
return false;
}
while(sizeOf($r) > 0)
{
if (!teacherExists($teacherObjArray, $teacherName)) {
$T = new Teacher($teachernName, $teacherMaxLoad, $classPeriod);
$T->LName = $teacherName;
$T->MaxLoad = $teacherMaxLoad;
$T->addPeriod($classPeriod);
array_push($teacherObjArray, $T);
//create course object
$C = new Course($courseNumber, $courseName, $teacherName, $classPeriod);
$C->CourseNumber=$courseNumber;
$C->CourseName=$courseName;
$C->CourseTeacher=$teacherName;
$C->CoursePeriod=$classPeriod;
maintenance($r, $teacherName, $classPeriod, $cn);
}
//updates already existing object in array of objects
elseif (teacherExists($teacherObjArray, $teacherName))
{
//get teacher object where its LName property is equal to $teacherName
$T->addPeriod($classPeriod);
maintenance($r, $teacherName, $classPeriod, $cn);
}
}
$rrepresent?