php method to delete the last digit of a string: 1. Use the [substr()] function, the code is [substr($arr_str,0,strlen($arr_str)-1)]; 2. Use [ rtrim()] function, the code is [rtrim($arr_str, ",")].
php method to delete the last digit of the string:
Method one:
substr($arr_str,0,strlen($arr_str)-1);
Detailed explanation: Substr () Function grammar: String Substr (String $ String, Int $ Start [, Int $ LENGTH])
# stelen () Function: int strlen (string $string)Principle of this example: First use the strlen() function to determine the length of the string$arr_str, and then use the substr() function to $ Intercept arr_str to the penultimate digit of $arr_str. This removes the last ",".
Method 2:
substr($arr_str, 0, -1)
substr() function to cut off the last character in reverse order;
Method three:
rtrim($arr_str, ",")
rtrim()Function syntax:
string rtrim ( string $ str [, string $character_mask ] )
Related free learning recommendations:php programming (video)
The above is the detailed content of How to delete the last digit of a string in php. For more information, please follow other related articles on the PHP Chinese website!