/** * Return type of a given variable. * @param array || double || integer || json || object || string * @return string type of variable */ public static function type($data = false) { if ($data) { $dataType = gettype($data); if ($dataType === 'string') { if (Validate::isJson($data)) { $dataType = 'json'; } } return $dataType; } return false; }
/** * Format anything into json. * @param mixed input * @param boolean weither to prettify json string or not * @return string in json format */ public static function toJson($input = false, $pretty = false) { if ($input) { switch (Data::type($input)) { case 'array': $json = self::arrayToJson($input, $pretty); break; case 'object': $json = self::objectToJson($input, $pretty); break; default: $json = false; break; } if (Validate::isJson($json)) { return $json; } } return false; }