How to remove extra commas in php: 1. Remove the first and last commas through "trim($arr1,',')"; 2. Remove the last commas through "rtrim($arr1,',')" comma; 3. Remove the first comma through "ltrim($arr1,',')".
The operating environment of this article: Windows 7 system, PHP version 7.1, DELL G3 computer
php How to remove extra commas?
Remove commas after splicing strings in php
When using some string splicing, there will always be a comma at the end. Previously, the method was used to determine the removal. Comma, but it was so troublesome. Later I found a very simple way to use trim to remove
$arr1 = trim($arr1,','); //移除首尾的逗号 $arr1 = rtrim($arr1,','); //移除尾的逗号 $arr1 = ltrim($arr1,','); //移除首的逗号 echo $arr1;
and this solved the problem
Recommended study: "PHP Video Tutorial"
The above is the detailed content of How to remove extra commas in php. For more information, please follow other related articles on the PHP Chinese website!