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: 38:
<?php
namespace Teto\Object;
class Helper
{
public static function toArray($ary_or_obj, $is_toplevel = true)
{
if ($ary_or_obj instanceof ToArrayInterface) {
return $ary_or_obj->toArray();
}
if (!is_array($ary_or_obj) && !($ary_or_obj instanceof \Traversable)) {
return $is_toplevel ? null : $ary_or_obj;
}
$array = [];
foreach ($ary_or_obj as $i => $elm) {
$array[$i] = Helper::toArray($elm, false);
}
return $array;
}
}