In this example, I have shared how to explode and trim whitespace in PHP. You can do the following using array_map() Function:
1 | $new_arr = array_map('trim', explode(',', $str)); |
Another solution:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | $keywords = "one, two , three , four"; $keyword_array=explode(",", trim($keywords)); print_r($keyword_array); //Output will be /* Array ( [0] => one [1] => two [2] => three [3] => four ) */ |
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.