PHP code example of devmakerlab / entities

1. Go to this page and download the library: Download devmakerlab/entities library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

devmakerlab / entities example snippets


use DevMakerLab\Entity;

class Human extends Entity
{
    public string $name;
    public int $age;
}

$human = new Human([
    'name' => 'Bob',
    'age' => 42,
]);

echo $human->name; // Bob
echo $human->age; // 42

use DevMakerLab\EntityList;

class People extends EntityList
{
    public function getYoungest(): Human
    {       
        $entities = $this->entities;

        uasort($entities, function ($a, $b) {
            if ($a->age === $b->age) {
                return 0;
            }
    
            return ($a > $b) ? -1 : 1;
        });

        return array_pop($entities);
    }
}

$bob = new Human(['name' => 'Bob', 'age' => 45]);
$junior = new Human(['name' => 'Junior', 'age' => 21]);
$jane = new Human(['name' => 'Jane', 'age' => 31]);

$people = new People([$bob, $junior]);
$people[] = $jane;

echo $people[0]->name; // Bob
echo $people[1]->name; // Junior
echo $people->getYoungest()->name; // Junior