Gabriel Gomez Gabriel Gomez - 2 months ago 4x
PHP Question

PHP: Divide a string into parts, and put it into an array

my name is Gabriel, it's my first post/question in this BIG community.
First, i'm from Argentina, so my english isn't the best.

My problem is the next, guess that I have this string in my php file:

$exampleString = "1,2,3,4,5,6,7,8,9,10";

Now, I want to know if it's possible to divide the string by coma, and put it into an array.

I'm new in PHP so I'm not sure at all about the functions.

Thanks to everyone!


What should I do if the separator is [ 1 ] [ 2 ] [ 3 ] [ 4 ] instead of a coma?


There sure is! It's a little function called explode() and it makes the array for you!

$exampleString = "1,2,3,4,5,6,7,8,9,10";
$array = explode(',', $exampleString);

What it does is simple, you specify what you want to "explode" on (,), and the source string ($exampleString) and it works it's magic.