How to print the value of comma

WBOY
Release: 2023-03-02 09:42:01
Original
906 people have browsed it

I use implode to grab the field value of the checkbox
After inputting it into mysql
The value of the field is assumed to be 1,2,3

But how to make it display the values ​​between commas separately when echo is displayed?
1 2 3

Reply content:

I use implode to grab the field value of the checkbox
After inputting it into mysql
The value of the field is assumed to be 1,2,3

But how to make it display the values ​​between commas separately when echo is displayed?
1 2 3

<code><?php
$string1 = "1,2,3"; 
$array = explode(',',$string1);//以','对$string1进行切割 
echo $array[0]; //1
echo "\n";
echo $array[1]; //2
echo "\n";
echo $array[2]; //3
echo "\n";
$string2 = implode(' ',$array);//以' '对$array进行合并
echo $string2;  //1 2 3
?>
</code>
Copy after login

Hope it helps you

Isn’t it possible to use explode() to split it into arrays and then read them?
If you don’t want to loop the output, you can explode() and then implode() again.

Related labels:
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!