a::json PHP Method

json() static public method

Converts an array to a JSON string It's basically a shortcut for json_encode()
static public json ( array $array ) : string
$array array The source array
return string The JSON string
    static function json($array)
    {
        return @json_encode((array) $array);
    }

Usage Example

Example #1
0
 /**
  * Set a new cookie
  * 
  * <code>
  * 
  * cookie::set('mycookie', 'hello', 60);
  * // expires in 1 hour
  * 
  * </code>
  * 
  * @param  string  $key The name of the cookie
  * @param  string  $value The cookie content
  * @param  int     $lifetime The number of minutes until the cookie expires
  * @param  string  $path The path on the server to set the cookie for
  * @param  string  $domain the domain 
  * @param  boolean $secure only sets the cookie over https
  * @param  boolean $httpOnly avoids the cookie to be accessed via javascript
  * @return boolean true: the cookie has been created, false: cookie creation failed
  */
 public static function set($key, $value, $lifetime = 0, $path = '/', $domain = null, $secure = false, $httpOnly = true)
 {
     // convert array values to json
     if (is_array($value)) {
         $value = a::json($value);
     }
     // hash the value
     $value = static::hash($value) . '+' . $value;
     // store that thing in the cookie global
     $_COOKIE[$key] = $value;
     // store the cookie
     return setcookie($key, $value, static::lifetime($lifetime), $path, $domain, $secure, $httpOnly);
 }
All Usage Examples Of a::json