public static function buildObject($var, $format = false){
        if (is_array($var)) {
            $returnValue = '{';
            $i = 1;
            foreach($var as $k => $v){
                $k = is_int($k)?'"'.json_encode($k).'"':json_encode($k);
                $returnValue .= $k.':'.self::buildObject($v, $format);
                $returnValue .= ($i < count($var)) ? ',' : '';
                $returnValue .= $format ? PHP_EOL : '';
                $i++;
            }
            $returnValue .= '}';
        } else {
            
            // Some versions of PHP simply fail
            // when encoding non UTF-8 data. Some other
            // versions return null... If it fails, simply
            // reproduce a single failure scenario.
            $returnValue = @json_encode($var);
            
            if ($returnValue === false) {
                $returnValue = json_encode(null);
            }
        }
        
        return $returnValue;
    }
public static function buildObject($var, $format = false){
        if (is_array($var)) {
            $returnValue = '{';
            $i = 1;
            foreach($var as $k => $v){
                $k = is_int($k)?'"'.json_encode($k).'"':json_encode($k);
                $returnValue .= $k.':'.self::buildObject($v, $format);
                $returnValue .= ($i < count($var)) ? ',' : '';
                $returnValue .= $format ? PHP_EOL : '';
                $i++;
            }
            $returnValue .= '}';
        } else {
            
            // Some versions of PHP simply fail
            // when encoding non UTF-8 data. Some other
            // versions return null... If it fails, simply
            // reproduce a single failure scenario.
            $returnValue = @json_encode($var);
            
            if ($returnValue === false) {
                $returnValue = json_encode(null);
            }
        }
        
        return $returnValue;
    }
public static function buildObject ( $ var , $ format = false ) { if ( is_array ( $ var ) ) { $ returnValue = '{' ; $ i = 1 ; foreach ( $ var as $ k => $ v ) { $ k = is_int ( $ k ) ? '"' . json_encode ( $ k ) . '"' : json_encode ( $ k ) ; $ returnValue .= $ k . ':' . self :: buildObject ( $ v , $ format ) ; $ returnValue .= ( $ i < count ( $ var ) ) ? ',' : '' ; $ returnValue .= $ format ? PHP_EOL : '' ; $ i ++ ; } $ returnValue .= '}' ; } else { // Some versions of PHP simply fail // when encoding non UTF-8 data. Some other // versions return null... If it fails, simply // reproduce a single failure scenario. $ returnValue = @ json_encode ( $ var ) ; if ( $ returnValue === false ) { $ returnValue = json_encode ( null ) ; } } return $ returnValue ; }
converts a php array or string into a javascript format

@access public
@author Joel Bout, <joel@taotesting.com>
@param  mixed $var
@param  boolean format
@return string
converts a php array or string into a javascript format