First letter is number in string

后端 未结 5 2050
忘掉有多难
忘掉有多难 2020-12-11 01:55

I was trying to find a quick and easy method to check if the first letter in a string is a number. A lot of the functions and methods I\'ve seen on S.O seem over complicated

5条回答
  •  难免孤独
    2020-12-11 02:34

    It won't work on empty strings, so you should check the offset prior accessing it:

    $result = isset($string[0]) ? is_numeric($string[0]) : false;
    

提交回复
热议问题