Finding the 2nd, 3rd, 4th etc. phrase in a comma-separated array?
internetheaven
2:03 pm on Oct 13, 2014 (gmt 0)
If I have an array with:
phrase 1, phrase 2, phrase 3, phrase 4
How do I split it up to have them retrieved individually? I can get phrase 1 okay by searching for the first comma and cutting. But what about the rest?
Is the space after the comma delimiter a reality/problem?
omoutop
1:41 pm on Oct 15, 2014 (gmt 0)
use trim() for the space after the comma
echo trim($myarray[0]); // phrase 1
assuming that your extra space is not needed
paulg
10:11 am on Dec 9, 2014 (gmt 0)
Use this function explode() function breaks a string into an array.The "separator" parameter cannot be an empty string. $mystr='ph1,ph2,ph3'; $myarray=explode(',',$mystr); echo $myarray[0]; echo $myarray[1];