分享一个函数,转小驼峰,php7.4以上
/** * 转成小驼峰 如:third_party => thirdParty third/party => thirdParty * * @param string $thing * @return string */ function camel_case(string $thing): string { return preg_replace_callback_array([ '#^[a-z]#' => static fn(array $piece): string => strtolower($piece[0]), '#_([a-z])#' => static fn(array $piece): string => strtoupper($piece[1]), '#/([a-z])#' => static fn(array $piece): string => strtoupper($piece[1]) ], $thing) ?? $thing; }
|