note 84206 added to function.ArrayObject-construct
| From: | kjarli at gmail dot com | Date: | Thu, 03 Jul 2008 10:11:12 +0000 |
| Subject: | note 84206 added to function.ArrayObject-construct | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-141107@lists.php.net to get a copy of this message | ||
This extend allows multidimensional arrays to be converted aswell. It also returns 'Array'
when echoed (unlike ArrayObject which gives an error).
<?php
/**
* @author iltar van der berg
* @version 1.0.1
*/
class RecursiveArrayObject extends ArrayObject
{
/**
* overwrites the ArrayObject constructor for
* iteration through the "array". When the item
* is an array, it creates another self() instead
* of an array
*
* @param Array $array data array
*/
public function __construct(Array $array)
{
foreach($array as $key => $value) {
if(is_array($value)){
$value = new self($value);
}
$this->offsetSet($key, $value);
}
}
/**
* returns Array when printed (like "echo array();")
* instead of an error
*
* @return string
*/
public function __ToString()
{
return 'Array';
}
}
?>
----
Server IP: 213.249.64.162
Probable Submitter: 213.126.138.2
----
Manual Page -- http://www.php.net/manual/en/function.ArrayObject-construct.php
Edit -- https://master.php.net/note/edit/84206
Del: integrated -- https://master.php.net/note/delete/84206/integrated
Del: useless -- https://master.php.net/note/delete/84206/useless
Del: bad code -- https://master.php.net/note/delete/84206/bad+code
Del: spam -- https://master.php.net/note/delete/84206/spam
Del: non-english -- https://master.php.net/note/delete/84206/non-english
Del: in docs -- https://master.php.net/note/delete/84206/in+docs
Del: other reasons-- https://master.php.net/note/delete/84206
Reject -- https://master.php.net/note/reject/84206
Search -- https://master.php.net/manage/user-notes.php