35 行
1.1 KiB
PHP
35 行
1.1 KiB
PHP
<?php
|
|
if (!function_exists("str_starts_with")) {
|
|
function str_starts_with (string $haystack, string $needle): bool {
|
|
return (string)$needle !== "" && strncmp($haystack, $needle, strlen($needle)) === 0;
|
|
}
|
|
}
|
|
|
|
if (!function_exists("str_ends_with")) {
|
|
function str_ends_with (string $haystack, string $needle): bool {
|
|
$needle_len = strlen($needle);
|
|
return ($needle_len === 0 || 0 === substr_compare($haystack, $needle, - $needle_len));
|
|
}
|
|
}
|
|
|
|
if (!function_exists("str_contains")) {
|
|
function str_contains (string $haystack, string $needle): bool {
|
|
return $needle !== "" && mb_strpos($haystack, $needle) !== false;
|
|
}
|
|
}
|
|
|
|
if (!function_exists("array_key_first")) {
|
|
function array_key_first (array $array): int|string|null {
|
|
if (!is_array($array) || empty($array)) return NULL;
|
|
return array_keys($array)[0];
|
|
}
|
|
}
|
|
|
|
if (!function_exists("array_key_last")) {
|
|
function array_key_last (array $array): int|string|null {
|
|
if (!is_array($array) || empty($array)) return NULL;
|
|
return array_keys($array)[count($array)-1];
|
|
}
|
|
}
|
|
?>
|