0

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.

2

2 Answers 2

2

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

Sign up to request clarification or add additional context in comments.

Comments

1

You can use explode function for that

$array = explode(":", $str);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.