Getting the first character of a string with $str[0]

前端 未结 9 1119
余生分开走
余生分开走 2020-11-28 21:04

I want to get the first letter of a string and I\'ve noticed that $str[0] works great. I am just not sure whether this is \'good practice\', as that notation is

9条回答
  •  眼角桃花
    2020-11-28 21:58

    Speaking as a mere mortal, I would stick with $str[0]. As far as I'm concerned, it's quicker to grasp the meaning of $str[0] at a glance than substr($str, 0, 1). This probably boils down to a matter of preference.

    As far as performance goes, well, profile profile profile. :) Or you could peer into the PHP source code...

提交回复
热议问题