public function highestHappinessChange(array $people) { $keys = array_keys($people); $highest = null; $table = null; foreach ($this->permutations->calculate($keys) as $k => $permutation) { $peopleAtTable = []; foreach ($permutation as $index) { $peopleAtTable[] = $people[$index]; } $table = new Table($peopleAtTable); if (!$highest || $table->happinessChange() > $highest->happinessChange()) { $highest = $table; } } return $highest; }