How to convert string with delimiter into array – PHP

<?php
// Example 1
$testValues  = "test1 test2 test3 test4 test5";
$testArray = explode(" ", $testValues);
print_r($testArray);
//Array ( [0] => test1 [1] => test2 [2] => test3 [3] => test4 [4] => test5 )

// Example 2
$testValues  = "test1,test2,test3,test4,test5";
$testArray = explode(",", $testValues);
print_r($testArray);
//Array ( [0] => test1 [1] => test2 [2] => test3 [3] => test4 [4] => test5 )
?>
Share

Leave a Reply

Your email address will not be published. Required fields are marked *