public static function arrayToString($arr) { $result = ''; if(is_array($arr) && count($arr) > 0) { foreach($arr as $key => $value) { $tempValue = '\'\''; if(is_null($value)) { $value = 'null'; } else if(is_array($value)) { $tempValue = self::arrayToString($value); } else { if(is_string($value)) { $tempValue = '\'' . strval($value) . '\''; } else { $tempValue = strval($value); } } if(is_string($key)) { $result .= ('\'' . $key . '\'' . '=>' . $tempValue) . ','; } else { $result .= (strval($key) . '=>' . $tempValue) . ','; } } if(strlen($result) > 0) { $result = 'array(' . substr($result, 0, strlen($result) - 1) . ')'; } else { $result = 'array()'; } } return $result; }
php 打印数组为字符串,php 数组转换为字符串
最新推荐文章于 2021-04-06 19:34:40 发布