I'm trying to split a concatenated string of key1value1key2value2 The problem is I can't know in which order they are
$k = preg_split("/(name|age|sex)/", "nameJohnage27sexM");
var_dump($k);
$k = preg_split("/(sex|name|age)/", "age27sexM");
var_dump($k);
So I can't know if the age or name will be 1st or 2nd index of $k, don't even know also if "name" key is in the string, there can be a limited set of key
How to do?
edit: solved like this, tx mario
for ($i=1, $n=count($k)-1; $i<$n; $i+=2) {
$s[$k[$i]] = $k[$i+1];
}
var_dump($s);