process($data); // Useful function function array_median($array) { $count = count($array); if($count === 0) { return null; } $middle = floor($count / 2); sort($array, SORT_NUMERIC); $median = $array[$middle]; // assume an odd # of items // Handle the even case by averaging the middle 2 items if ($count % 2 == 0) { $median = ($median + $array[$middle - 1]) / 2; } return $median; } // Useful function function array_mean($array) { $count = count($array); if($count === 0) { return null; } return array_sum($array) / $count; } // Useful function function array_standard_deviation($array) { $count = count($array); if ($count === 0) { return null; } $mean = array_mean($array); $variance = 0; foreach($array as $i) { $variance += pow(($i - $mean), 2); } return round(sqrt($variance / $count), 2); } /** * Convert a local datetime string to a UTC datetime string. * * @param string $local_datetime Local datetime string. * @param string $local_time_zone The local time zone to convert from. * * @return string The UTC datetime string. */ function get_utc_datetime($local_datetime, $local_time_zone, $format = 'Y-m-d H:i:s') { $local_time_zone = new DateTimeZone($local_time_zone); $utc_time_zone = new DateTimeZone('UTC'); $date_time = new DateTime($local_datetime, $local_time_zone); $date_time->setTimezone($utc_time_zone); return $date_time->format($format); } /** * Convert a UTC datetime string to a local datetime string. * * @param string $utc_datetime Local datetime string. * @param string $local_time_zone The local time zone to convert from. * * @return string The local datetime string. */ function get_local_datetime($utc_datetime, $local_time_zone, $format = 'Y-m-d H:i:s') { $local_time_zone = new DateTimeZone($local_time_zone); $utc_time_zone = new DateTimeZone('UTC'); $date_time = new DateTime($utc_datetime, $utc_time_zone); $date_time->setTimezone($local_time_zone); return $date_time->format($format); } /** * Encode data with base64url (RFC 4648 §5). * * @param string $data The data to encode. * @return string The base64url encoded string. */ function base64url_encode($data) { return rtrim(strtr(base64_encode($data), '+/', '-_'), '='); } /** * Decode a base64url encoded string (RFC 4648 §5). * * @param string $data The base64url encoded string. * @return string|false The decoded data or false on failure. */ function base64url_decode($data) { $b64 = strtr($data, '-_', '+/'); return base64_decode(str_pad($b64, strlen($b64) % 4 === 0 ? strlen($b64) : strlen($b64) + 4 - strlen($b64) % 4, '=', STR_PAD_RIGHT)); }