03-24-2008, 01:31 AM
|
#1 (permalink)
|
|
The Contributor
Join Date: Nov 2007
Location: France, near Paris
Posts: 53
Thanks: 6
|
array to object
Hi !
I would like to quickly transform an array into an object and whatever the keys presents into the array. I want it dynamic and not static, key by key.
I've thought to this method:
PHP Code:
<?php foreach($params as $key => $val) { if(isset($this->$key)) $this->$key = $val; } ?>
but it doesn't work. It cause no error but the $this->$key never exists.
My array is like:
id => 1
title => "test Site"
url => "http://www.monsite.com"
story => "blablabla"
and my object attributes are:
PHP Code:
<?php private $id; private $title; private $url; private $story; ?>
Do you have any idea ?
Thank you !
|
|
|