- var_dump: documentation ( source)
- array_merge: documentation ( source)
- array_unique: documentation ( source)
<?php
class Student
{
private $classes;
public function __construct($classes)
{
$this->classes = $classes;
}
public function getClasses()
{
return $this->classes;
}
public function combineClasses(Student $otherStudent)
{
$allClasses = array_unique(array_merge($this->classes, $otherStudent->classes));
$this->classes = $allClasses;
$otherStudent->classes = $allClasses;
}
}
$mary = new Student(['CompSci2001', 'CompSci2002']);
$john = new Student(['CompSci2002', 'CompSci2003']);
$mary->combineClasses($john);
var_dump($mary->getClasses());
var_dump($john->getClasses());