recursivearrayobject
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?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';
}
}
?>
/**
* @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';
}
}
?>