The explode() is a builtin function which breaks a string into an array.
Syntax
1 |
explode ( string $delimiter , string $string [, int $limit = PHP_INT_MAX ] ) : array |
Example #1 explode() function
1 2 3 4 5 6 7 8 9 10 |
/* A string that doesn't contain the delimiter will simply return a one-length array of the original string. */ $input1 = "hello"; $input2 = "hello,there"; $input3 = ','; var_dump( explode( ',', $input1 ) ); var_dump( explode( ',', $input2 ) ); var_dump( explode( ',', $input3 ) ); |
Output
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
array(1) ( [0] => string(5) "hello" ) array(2) ( [0] => string(5) "hello" [1] => string(5) "there" ) array(2) ( [0] => string(0) "" [1] => string(0) "" ) |
That’s all, we hope this helped you!
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.