[[oktatas:programozás:php:php_oop|< PHP OOP]] ====== Objektumok tömbben ====== * **Szerző:** Sallai András * Copyright (c) Sallai András, 2021 * Licenc: [[https://creativecommons.org/licenses/by-sa/4.0/|CC Attribution-Share Alike 4.0 International]] * Web: https://szit.hu ===== Egyszerűen ===== id = $id; $this->name = $name; $this->city = $city; $this->salary = $salary; } } $employees = [ new Employee(1, "Dór Tamás", "Szeged", 2875000), new Employee(2, "Ber Ferenc", "Szolnok", 2375000) ]; print_r($employees); Futtatás: php -S localhost:8000 -t . ===== Kontrollerben ===== class Employee { public $id; public $name; public $city; public $salary; public function __construct($id, $name, $city, $salary) { $this->id = $id; $this->name = $name; $this->city = $city; $this->salary = $salary; } } class EmployeeController extends Controller { public function getEmployees() { $employees = [ new Employee(1, "Dór Tamás", "Szeged", 2875000), new Employee(2, "Ber Ferenc", "Szolnok", 2375000) ]; return view('home')->with('employees', $employees); } }