Forum Moderators: coopster
$sports="basketball,football,hockey,lacrosse,cricket";
Now say that I want to do a preg_split to return only the first two elements of this list "basketball football" How do I do it?
This is what I tried:
return preg_split (',', $sports, 2);
But it returned:
"basketball football hockey,lacrosse,cricket"
Any ideas?
Robin
It would return:
print $value1; // basketball
print $value2; // football,hockey,lacrosse,cricket
Note, the same thing would occur if you used
preg_split, even without the last parameter. The key here is twofold: You could use either function, explode or preg_split in this manner to achieve the results desired.