Sunday, 26 July 2015

Convert comma separated words into an array

Leave a Comment

Sometimes we want to convert a string into an array. String is comma separated words like adam, adam@yahoo.com, male.

You can do the string to array conversion easily with explode function in PHP.

<?php
$myString = "adam,adam@yahoo.com,male";
$myArray = explode(',', $myString);
print_r($myArray);
?>

Output:

Array
(
[0] => adam
[1] => adam@yahoo.com
[2] => male
)

This way you can convert string into array.

0 comments:

Post a Comment

.