php把字符串中大写字母转换成下划线间隔小写字母的方法,代码如下:
$name = 'getCourseDetailInfo';
/**
 * 将字符串内的大写字母转换成下划线加小写字母
 * @param string $str
 * @return string
 */
function strToUnderLineSpacing($str): string {
    $tmp_array = [];
    for ($i = 0; $i < strlen($str); $i++) {
        $ascii_code = ord($str[$i]);
        if ($ascii_code >= 65 && $ascii_code <= 90) {
            if ($i == 0) {
                $tmp_array[] = chr($ascii_code + 32);
            } else {
                $tmp_array[] = '_' . chr($ascii_code + 32);
            }
        } else {
            $tmp_array[] = $str[$i];
        }
    }
    return implode('', $tmp_array);
}
echo strToUnderLineSpacing($name);
输出:get_course_detail_info