0

I'm trying to split a string into an array such that if the string is z10k4m42 it would become

array('z' => 10, 'k' => 4, 'm' => 42)

Is this possible?

1
  • 3
    harsh and uninviting comments. even worse, snarky and counterproductive. Commented Oct 5, 2012 at 6:07

1 Answer 1

6

Try the below:

preg_match_all('/([a-z]+)(\d+)/', 'z10k4m42', $matches);
$ret = array_combine($matches[1], $matches[2]);
Sign up to request clarification or add additional context in comments.

3 Comments

This only makes an array with the numbers. The solution would be a mix with my (deleted) answer and yours :-)
This at least works for me. I got an array with chars as key and the following numbers as value. Isn't that what he wanted?
@TheDisintegrator Have you run the code and see the result? It should be what the op wants.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.