<?php
class Employee
{
public $name;
public $salary;
public function __construct($name,$salary)
{
$this->name = $name;
$this->salary = $salary;
}
}
class Student
{
public $name;
public $scholarship;
public function __construct($name, $scholarship)
{
$this->name = $name;
$this->scholarship = $scholarship;
}
}
$employee1 = new Employee('Sefer', 40.000);
$employee2 = new Employee('Edem', 30.000);
$employee3 = new Employee('Asia', 20.000);
$student1 = new Student('Roma', 100);
$student2 = new Student('Liza', 150);
$student3 = new Student('Sasha', 200);
$arr = [$employee1, $employee2, $student1, $student3, $employee3, $student2];
$sum = 0;
foreach ($arr as $elem) {
if ($elem instanceof Employee) {
for ($i = 0; $i < count($elem->salary); $i++) {
$sum += $elem[$i];
echo $sum;
}
}
}