function arrayeval($array, $level = 0) { $space = ''; for($i = 0; $i <= $level; $i++) { $space .= "/t"; } $evaluate = "Array/n$space(/n"; $comma = $space; foreach($array as $key => $val) { $key = is_string($key) ? '/''.addcslashes($key, '/'//').'/'' : $key; $val = !is_array($val) && (!preg_match("/^/-?/d+$/", $val) || strlen($val) > 12 || substr($val, 0, 1)=='0') ? '/''.addcslashes($val, '/'//').'/'' : $val; if(is_array($val)) { $evaluate .= "$comma$key => ".arrayeval($val, $level + 1); } else { $evaluate .= "$comma$key => $val"; } $comma = ",/n$space"; } $evaluate .= "/n$space)"; return $evaluate; }