- print_r: documentation ( source)
<?php
/**
* @author Iltar van der Berg
* @version 2.0.0
*/
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 static($value);
}
$this->offsetSet($key, $value);
}
}
/**
* returns Array when printed (like "echo array();")
* instead of an error
*
* @return string
*/
public function __ToString()
{
return 'Array';
}
}
$array = array('1','2','3,');
$array = new RecursiveArrayObject($array);
print_r($array);