Home > Article > Backend Development > How to convert string to array using comma in php
php method to use commas to convert a string into an array: first create a PHP sample file; then use the "explode(",",$str)" method to break up a string into an array .
Recommended: "PHP Video Tutorial"
Strings are broken into arrays
<?php $str = "Hello world. I love php!"; print_r (explode(" ",$str)); ?>
Use explode to break up a string into an array. However, explode uses a certain character to break it up. For example, in the above example, the first parameter in the parentheses of explode is a space, and the second parameter is a space. is the string we are going to scramble, so concatenation means breaking the $str string into characters through spaces.
Because the content of our string is Hello world. I love php!
Each word is separated by a space, then after we break it up by spaces, our string will be It can be turned into an array.
If our Hello, world, Ilove, php!
are separated by commas, then we modify
explode(“,”,$str) first Just fill in the commas "," for each parameter.
The above is the detailed content of How to convert string to array using comma in php. For more information, please follow other related articles on the PHP Chinese website!