Home  >  Article  >  Backend Development  >  How to print the value of comma

How to print the value of comma

WBOY
WBOYOriginal
2016-12-01 01:27:17901browse

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>

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.

Statement:
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