public static function convertEncodingRecursive( $var, $to_encoding = NULL, $from_encoding = NULL )
    {
        $type = gettype($var);
        switch( $type ){
        case 'string':
            {
                return mb_convert_encoding($var,$to_encoding, $from_encoding);
            }
            break;
        case 'integer':
        case 'double':
        case 'boolean':
        case 'NULL':
        case 'unknown type':
            break;
        case 'array':
            {
                $newArray = array();
                foreach( $var as $key => $value ){
                    $value = self::convertEncodingRecursive( $value, $to_encoding, $from_encoding );
                    $newArray[ $key ] = $value;
                }
                return $newArray;
            }
            break;
        case 'object':
            {
                $newObject = clone $var;
                if ( $var instanceof \Traversable ){
                    foreach( $var as $key => $value ){
                        $value = self::convertEncodingRecursive( $value, $to_encoding, $from_encoding );
                        $newObject->$key = $value;
                    }
                    return $newObject;
                }
                else{
                    $obj_vars = get_object_vars( $var );
                    foreach( $obj_vars as $key => $value ){
                        $value = self::convertEncodingRecursive( $value, $to_encoding, $from_encoding );
                        $newObject->$key = $value;
                    }
                    return $newObject;
                }
            }
            break;
        }

        return $var;
    }