Dump all PHP variables
$all_vars = get_defined_vars();
print_r($all_vars);
Create an array for a range (e.g: array with number from 1 to 9)
$number = 9;
for ($i = 1; $i <= $number; ++$i) {
$array[] = $i;
}
Number to words in Bahasa Indonesia (intl extension needed)
$numberFormatter = new \NumberFormatter("id_ID", \NumberFormatter::SPELLOUT);
echo $numberFormatter->format('1075000');
// Print: satu juta tujuh puluh lima ribu
Redirect any URL without http to https:
if (defined('APP_ENV') && APP_ENV === 'production') {
if ((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off')
|| (isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == 443)
|| (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https')
|| (!empty($_SERVER['HTTP_CF_VISITOR']) && str_contains($_SERVER['HTTP_CF_VISITOR'], '"https"'))) {
return;
}
$host = $_SERVER['HTTP_HOST'] ?? '';
$uri = $_SERVER['REQUEST_URI'] ?? '/';
header('Location: https://' . $host . $uri, true, 301);
exit;
}