RE: [PHP] stdClass to array
| From: | Michael Sims | Date: | Wed, 12 Jan 2005 00:56:02 +0000 |
| Subject: | RE: [PHP] stdClass to array | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-206130@lists.php.net to get a copy of this message | ||
Cere Davis wrote:
> Hey folks,
>
> Does anyone know of a painless way to convert a stdClass object to an
> associative array in php?
Just cast it:
$arr = (array) $stdClassInstance;
> Also, I wonder, is there a way to "flatten" associative arrays in php?
> So say:
> $b=new array(s=>"S")
> $a=new array(a=>"A",b=>$b)
>
> goes to:
> $z=flatten($a);
> z turns to:
> (a=>"A", b=>$b, s=>"S");
array_merge()
http://www.php.net/manual/en/function.array-merge.php
HTH