PHP格式化打印:JSON字符串|对象|数组

/**
     * 格式化打印:JSON字符串|对象|数组
     * @param string|array $data
     */
    public static function Console($data)
    {
        if (is_string($data) && 0 < strlen($data) && self::isJson($data)) {
            echo json_encode(json_decode($data), JSON_PRETTY_PRINT);
        }elseif (!empty($data) && (is_array($data) || is_object($data))) {
            echo json_encode($data, JSON_PRETTY_PRINT);
        }else{
            var_dump($data);
        }

    }
    public static function isJson($string):bool
    {
        return is_string($string) && is_array(json_decode($string, true));
    }
原文地址:https://www.cnblogs.com/felixwan/p/15802022.html