Reputation: 105
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?
Upvotes: 0
Views: 129
Reputation: 160883
Try the below:
preg_match_all('/([a-z]+)(\d+)/', 'z10k4m42', $matches);
$ret = array_combine($matches[1], $matches[2]);
Upvotes: 6