note 24596 added to language.oop
| From: | hfuecks at pinkgoblin dot com | Date: | Thu, 22 Aug 2002 14:55:26 +0000 |
| Subject: | note 24596 added to language.oop | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-35365@lists.php.net to get a copy of this message | ||
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>" );
?>
--
http://www.php.net/manual/en/language.oop.php
http://master.php.net/manage/user-notes.php?action=edit+24596
http://master.php.net/manage/user-notes.php?action=delete+24596
http://master.php.net/manage/user-notes.php?action=reject+24596