我需要轉換的,像這樣的字符串,PHP中某些字符串操作的最有效方法?
'hello world' = 'helloWorld'
而且也反向相同,
'helloWorld' = 'hello world'
到目前爲止,所有我有兩個轉換是本作的第一,
$str = 'hello world';
$str = lcfirst(str_replace(' ', '', ucwords($str))); // helloWorld
而第二個,
$str = 'helloWorld';
$str = preg_split('/(?=[A-Z])/', $str);
$str = strtolower(implode(' ', $str)); // hello world
難道這不能實現更簡單或更高效嗎?
什麼是低效的呢?對我來說看起來很好 – Cyclone
最有效的方式是最可讀的,而不是失敗。不要因爲每個請求的0.04ms而讓你的代碼變得eye目結舌。 – Amelia