Reputation: 5626
I have string in the following format.
Option1:Option2:Option3:Option4
I want to get these items separated and put it into a array.
array(item1=>option1,item2=>option2,item3=>option3,item4=>option4)
etc.
is there a straight forward way to get this done using regular expressions with PHP.
Thanks in advance for sharing your experience with me.
Upvotes: 0
Views: 42
Reputation: 4118
Use $arr = explode(":", $string);
and then do this:
$result = array();
for ($i = 0; $i < count($arr); $i ++) {
$result['item' . $i] = $arr[$i];
}
and you should find $result
to be exactly what you want
Upvotes: 2