1. Go to this page and download the library: Download yiisoft/arrays 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/ */
use \Yiisoft\Arrays\ArrayAccessTrait;
class OfficeClassification implements \IteratorAggregate, \ArrayAccess, \Countable
{
use ArrayAccessTrait;
public array $data = [
'a' => 'Class A',
'b' => 'Class B',
'c' => 'Class C',
];
}
$classification = new OfficeClassification();
echo 'Count classes: ' . $classification->count() . "\n"; // 3
$iterator = $classification->getIterator();
while ($iterator->valid()) {
echo $iterator->current() . "\n"; // Class A, Class B, Class C
$iterator->next();
}
use \Yiisoft\Arrays\ArrayableTrait;
use \Yiisoft\Arrays\ArrayableInterface;
class Car implements ArrayableInterface
{
use ArrayableTrait;
public string $type = 'Crossover';
public string $color = 'Red';
public int $torque = 472;
}
$car = new Car();
$data = $car->toArray(['type', 'color']); // ['type' => 'Crossover', 'color' => 'Red']
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.