How to remove extra commas in php

藏色散人
Release: 2023-03-15 06:32:02
Original
2843 people have browsed it

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,',')".

How to remove extra commas in php

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;
Copy after login

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!

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!