1. Go to this page and download the library: Download midorikocak/arraytools 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/ */
midorikocak / arraytools example snippets
declare(strict_types=1);
namespace midorikocak\arraytools;
class User implements ArrayConvertableInterface, ArrayUpdateableInterface
{
use ArrayConvertableTrait;
use ArrayUpdateableTrait;
private ?string $id;
private string $username;
private string $email;
private string $password;
public function __construct(?string $id, string $username, string $email, string $password)
{
$this->id = $id;
$this->username = $username;
$this->password = $password;
$this->email = $email;
}
public function getId(): ?string
{
return $this->id;
}
public function setId(string $id)
{
$this->id = $id;
}
// Getters and setters
public function toArray(): array
{
$toReturn = [
'username' => $this->getUsername(),
'email' => $this->getEmail(),
'password' => $this->getPassword(),
];
if ($this->getId()) {
$toReturn['id'] = $this->getId();
}
return $toReturn;
}
public static function fromArray($array): User
{
$id = $array['id'] ?? null;
$username = $array['username'];
$email = $array['email'];
$password = $array['password'];
return new User($id, $username, $email, $password);
}
declare(strict_types=1);
namespace midorikocak\arraytools;
class User implements ArrayConvertableInterface
{
use ArrayConvertableTrait;
private ?string $id;
private string $username;
private string $email;
private string $password;
// rest