I have an array of objects
[new BalanceSheet('2018', '356743', '-56913', '189632', '122733'),
new BalanceSheet('2018', '4562343', '236913', '198732', '6552733'),
new BalanceSheet('2017', '2234643', '55913', '19435342', '855342733')
]
And i need to throw an exception when the first key in object are duplicate another -> 2018 === 2018
I understand how i can to get the key
class BalanceSheet {
public function __construct(string $year, ...) {
$this->year = $year;
...
}
public function getYear() {
return $this->year;
}
private function isDuplicateData($sheets) {
foreach ($sheets as $key => $sheet) {
echo $key . ' year = ' . $sheet->getYear();
}
}
but i don't understand what the easiest way to compare keys in isDuplicateData