PHP : Array to Object

I wrote a quick and simple function which allows you to quickly convert arrays to objects. It allows you to change an array like this :


To an object like this :

$a -> b;

The quickest way to do this is with typecasting:

$a = array('b');
$a = (object) $a;
//$a is now an object

Or below is a manual function to achieve it. Have fun!

function array_to_object($array = array()) {
	if (!empty($array)) {
		$data = false;
		foreach ($array as $akey => $aval) {
			$data -> {$akey} = $aval;
		return $data;
	return false;