function ss_array_as_string (&$array, $column = 0) { $str = "Array(n"; while(list($var, $val) = each($array)){ for ($i = 0; $i < $column+1; $i++){ $str .= " "; } $str .= $var. '==>' ; $str .= ss_as_string($val, $column+1)." n"; } for ($i = 0; $i < $column; $i++){ $str .= " "; } return $str.); } function ss_object_as_string (&$object, $column = 0) { if (empty($object->classname)) { return "$object"; } else { $str = $object->classname."( n"; while (list(,$var) = each($object->persistent_slots)) { for ($i = 0; $i < $column; $i++){ $str .= " "; } global $$var; $str .= $var. '==>' ; $str .= ss_as_string($$var, column+1)." n"; } for ($i = 0; $i < $column; $i++){ $str .= " "; } return $str.')'; } } function ss_as_string (&$thing, $column = 0) { if (is_object($thing)) { return ss_object_as_string($thing, $column); } elseif (is_array($thing)) { return ss_array_as_string($thing, $column); } elseif (is_double($thing)) { return "Double(".$thing.")"; } elseif (is_long($thing)) { return "Long(".$thing.")"; } elseif (is_string($thing)) { return "String(".$thing.")"; } else { return "Unknown(".$thing.")"; } }
需要的时候,在程序中简单地加入下面的一条代码即可查看程序中的所使用的变量(包括数组和对象)的类型和值
echo ss_as_string($my_variable);
使用下面的语句,我们可以直接查看程序中所有的变量的值
echo ss_as_string($GLOBALS);