- var_dump: documentation ( source)
- array_merge: documentation ( source)
- array_fill_keys: documentation ( source)
<?php
class Auth_Model_User
{
/**
* Allowed fields
*
* @var array
*/
protected $_fields = array(
'id_acl_user',
'role',
'username',
'email',
'password_changed_at',
);
/**
* Userdata
*
* @var array
*/
protected $_data = array();
public function __construct($data = null)
{
$this->_data['role'] = 'bar';
}
/**
* @return array
*/
public function toArray()
{
return array_merge(array_fill_keys($this->_fields, null), $this->_data);
}
}
$user = new Auth_Model_User();
var_dump($user->toArray());