src/PHPToJS.php
public static function render($mixed)
    {
        if (!is_array($mixed) && !is_object($mixed)) {
            return strpos(str_replace(' ', '', $mixed), 'function(') === 0 ? $mixed : json_encode($mixed);
        }

        $isNumArr = array_keys((array) $mixed) === range(0, count((array) $mixed) - 1);
        $isObject = is_object($mixed) || (!$isNumArr && !empty($mixed));

        $r = array();
        $i = 0;
        foreach ($mixed as $k => $m) {
            $r[$i] = ($isObject ? self::renderObjectKey($k).':' : '').self::render($m);
            ++$i;
        }

        return  ($isObject ? '{' : '[').implode(',', $r).($isObject ? '}' : ']');
    }
public static function render($mixed)
    {
        if (!is_array($mixed) && !is_object($mixed)) {
            return strpos(str_replace(' ', '', $mixed), 'function(') === 0 ? $mixed : json_encode($mixed);
        }

        $isNumArr = array_keys((array) $mixed) === range(0, count((array) $mixed) - 1);
        $isObject = is_object($mixed) || (!$isNumArr && !empty($mixed));

        $r = array();
        $i = 0;
        foreach ($mixed as $k => $m) {
            $r[$i] = ($isObject ? self::renderObjectKey($k).':' : '').self::render($m);
            ++$i;
        }

        return  ($isObject ? '{' : '[').implode(',', $r).($isObject ? '}' : ']');
    }
public static function render ( $ mixed ) { if ( ! is_array ( $ mixed ) && ! is_object ( $ mixed ) ) { return strpos ( str_replace ( ' ' , '' , $ mixed ) , 'function(' ) === 0 ? $ mixed : json_encode ( $ mixed ) ; } $ isNumArr = array_keys ( ( array ) $ mixed ) === range ( 0 , count ( ( array ) $ mixed ) - 1 ) ; $ isObject = is_object ( $ mixed ) || ( ! $ isNumArr && ! empty ( $ mixed ) ) ; $ r = array ( ) ; $ i = 0 ; foreach ( $ mixed as $ k => $ m ) { $ r [ $ i ] = ( $ isObject ? self :: renderObjectKey ( $ k ) . ':' : '' ) . self :: render ( $ m ) ; ++ $ i ; } return ( $ isObject ? '{' : '[' ) . implode ( ',' , $ r ) . ( $ isObject ? '}' : ']' ) ; }
Render the variable's content from PHP to Javascript

@param mixed $mixed

@return string Javascript code
Render the variable s content from PHP to Javascript