note 24596 deleted from language.oop by didou
| From: | didou@php.net | Date: | Sun, 07 Dec 2003 02:38:47 +0000 |
| Subject: | note 24596 deleted from language.oop by didou | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-61545@lists.php.net to get a copy of this message | ||
Note Submitter: hfuecks@pinkgoblin.com
----
If you want to convert an array (for example) to an object, you can do something like this, using
the reserved stdClass for data;
<?php
$array = array ( "one" =>"red", "two" => "blue" );
$object = new stdClass ();
foreach ( $array as $key => $val ) {
$object->{$key}=$val;
}
echo ( "<pre>" );
print_r ( $object );
echo ( "</pre>" );
?>