How to get the last char of a string in PHP?

前端 未结 12 1417
说谎
说谎 2020-12-04 05:24

I need to get the last character of a string. Say I have \"testers\" as input string and I want the result to be \"s\". how can I do that in PHP?

12条回答
  •  攒了一身酷
    2020-12-04 05:46

    I'd advise to go for Gordon's solution as it is more performant than substr():

    outputs something like

     ---------------------------------- 
     10000000 repetitions...
     ----------------------------------
    
     substr() took 2.0285921096802seconds 
     array access took 1.7474739551544seconds
    

提交回复
热议问题