public static function getJSObject($data = [], $quoteKey = false)
    {
        if ($data === null) {
            return 'null';
        };

        $output = '';

        switch (gettype($data)) {
            case 'boolean':
                $output .= $data ? 'true' : 'false';
                break;

            case 'float':
            case 'double':
            case 'integer':
                $output .= $data + 0;
                break;

            case 'array':
                if (!static::isAssociativeArray($data)) {
                    $child = [];

                    foreach ($data as $value) {
                        $child[] = static::getJSObject($value, $quoteKey);
                    }

                    $output .= '[' . implode(',', $child) . ']';
                    break;
                }
                // Go to next body

            case 'object':
                $array = is_object($data) ? get_object_vars($data) : $data;

                $row = [];

                foreach ($array as $key => $value) {
                    $key = json_encode($key);

                    if (!$quoteKey) {
                        $key = substr(substr($key, 0, -1), 1);
                    }

                    $row[] = $key . ':' . static::getJSObject($value, $quoteKey);
                }

                $output .= '{' . implode(',', $row) . '}';
                break;

            default:  // anything else is treated as a string
                return strpos($data, '\\') === 0 ? substr($data, 1) : json_encode($data);
                break;
        }

        return $output;
    }
public static function getJSObject($data = [], $quoteKey = false)
    {
        if ($data === null) {
            return 'null';
        };

        $output = '';

        switch (gettype($data)) {
            case 'boolean':
                $output .= $data ? 'true' : 'false';
                break;

            case 'float':
            case 'double':
            case 'integer':
                $output .= $data + 0;
                break;

            case 'array':
                if (!static::isAssociativeArray($data)) {
                    $child = [];

                    foreach ($data as $value) {
                        $child[] = static::getJSObject($value, $quoteKey);
                    }

                    $output .= '[' . implode(',', $child) . ']';
                    break;
                }
                // Go to next body

            case 'object':
                $array = is_object($data) ? get_object_vars($data) : $data;

                $row = [];

                foreach ($array as $key => $value) {
                    $key = json_encode($key);

                    if (!$quoteKey) {
                        $key = substr(substr($key, 0, -1), 1);
                    }

                    $row[] = $key . ':' . static::getJSObject($value, $quoteKey);
                }

                $output .= '{' . implode(',', $row) . '}';
                break;

            default:  // anything else is treated as a string
                return strpos($data, '\\') === 0 ? substr($data, 1) : json_encode($data);
                break;
        }

        return $output;
    }
public static function getJSObject ( $ data = [ ] , $ quoteKey = false ) { if ( $ data === null ) { return 'null' ; } ; $ output = '' ; switch ( gettype ( $ data ) ) { case 'boolean' : $ output .= $ data ? 'true' : 'false' ; break ; case 'float' : case 'double' : case 'integer' : $ output .= $ data + 0 ; break ; case 'array' : if ( ! static :: isAssociativeArray ( $ data ) ) { $ child = [ ] ; foreach ( $ data as $ value ) { $ child [ ] = static :: getJSObject ( $ value , $ quoteKey ) ; } $ output .= '[' . implode ( ',' , $ child ) . ']' ; break ; } // Go to next body case 'object' : $ array = is_object ( $ data ) ? get_object_vars ( $ data ) : $ data ; $ row = [ ] ; foreach ( $ array as $ key => $ value ) { $ key = json_encode ( $ key ) ; if ( ! $ quoteKey ) { $ key = substr ( substr ( $ key , 0 , - 1 ) , 1 ) ; } $ row [ ] = $ key . ':' . static :: getJSObject ( $ value , $ quoteKey ) ; } $ output .= '{' . implode ( ',' , $ row ) . '}' ; break ; default : // anything else is treated as a string return strpos ( $ data , '\\' ) === 0 ? substr ( $ data , 1 ) : json_encode ( $ data ) ; break ; } return $ output ; }
Method to get a JavaScript object notation string from an array

@param mixed $data     The data to convert to JavaScript object notation
@param bool  $quoteKey Quote json key or not.

@return string JavaScript object notation representation of the array

@since  2.0
Method to get a JavaScript object notation string from an array