function parse_name(string $name, int $type = 0, bool $ucfirst = true): string
{
if ($type) {
$name = preg_replace_callback('/_([a-zA-Z])/',
// 通常: $matches[0]是完成的匹配
// $matches[1]是第一個捕獲子組的匹配
// 以此類推
function ($match) {
return strtoupper($match[1]); //$match[0] = '_Z'; , 也就是說函數的返回值會把match[0]完成匹配的值替換掉
},
$name);
// return $ucfirst ? ucfirst($name) : lcfirst($name);
return $name;
}
return strtolower(trim(preg_replace("/[A-Z]/", "_\\0", $name), "_")); //as__zy
}
//echo parse_name('As_Zy', 0); //As__Zy
echo parse_name('As_Zy', 1); //AsZy