How to split a string into array by delimiter with PHP

2 Answers

0 votes
$s = "PHP Java Python C";
$arr = explode(" ", $s);
 
echo $arr[0] . "\n";
echo $arr[1] . "\n";
echo $arr[2] . "\n";
echo $arr[3] . "\n";


/*
run:
 
PHP
Java
Python
C

*/

 



answered Oct 12, 2018 by avibootz
edited Aug 28 by avibootz
0 votes
$s = "PHP,Java,Python,C";
$arr = explode(",", $s);
 
foreach ($arr as $item) 
    echo $item . "\n";
 
 
/*
run:
 
PHP
Java
Python
C
 
*/

 



answered Oct 12, 2018 by avibootz
edited Aug 28 by avibootz

Related questions

1 answer 179 views
...