object to array
1.0.0
object-to-array adalah cara sederhana untuk mengubah object to array .
$ composer require polidog/object-to-array
<?php
use function PolidogObjectToArrayobject_to_array;
$date = new DateTime();
$dateArray = object_to_array($data);
var_dump($dataArray);
<?php
use PolidogObjectToArrayToArrayTrait;
class User
{
use ToArrayTrait;
private int $id;
private string $name;
private DateTimeInterface $createdAt;
/**
* User constructor.
* @param int $id
* @param string $name
*/
public function __construct(int $id, string $name)
{
$this->id = $id;
$this->name = $name;
$this->createdAt = new DateTime();
}
}
$user = new User(1, 'polidog');
var_dump($user->__toArray());