< PHP OOP

Objektumok tömbben

Szerző: Sallai András

Copyright © Sallai András, 2021

Licenc: CC Attribution-Share Alike 4.0 International

Web: https://szit.hu

Egyszerűen

<?php 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; } } $employees = [ new Employee(1, "Dór Tamás", "Szeged", 2875000), new Employee(2, "Ber Ferenc", "Szolnok", 2375000) ]; print_r($employees);

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); } }