Convert strings to an array – PHP

<?php
 $testString = "FirstName,MiddleName,LastName";
 $testArray	 = split(",",$testString);
 print_r($testArray);
 //Array ( [0] => FirstName [1] => MiddleName [2] => LastName )
?>
<?php
 $testString = "FirstName MiddleName,LastName";
 list($first, $middle, $last) = split('[  ,]', $testString);
 echo "First Name: $first; MiddleName: $middle; LastName: $last";
?>
Share

Leave a Reply

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