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 generally used with arrays. This feature doesn't seem to be very well documented so I'm turning to you guys to tell me if it's all right – in all respects – to use this notation?
Or should I just stick to the good ol' substr($str, 0, 1)
?
Also, I noted that curly braces ($str{0}
) works as well. What's up with that?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…