时间:2021-07-01 10:21:17 帮助过:6人阅读
$str = 'a,100,b,32,c,10,d,20';$res_str = implode(',',array_map(create_function('$v', 'return implode("=>",$v);'), array_chunk(explode(',', $str), 2)));$res = eval("return array($res_str);");echo '';print_r($res);echo '';/*Array( [a] => 100 [b] => 32 [c] => 10 [d] => 20)*/
------解决方案--------------------
直接的函数没有,恶心的代码有很多...
$Str = 'a,100,b,32,c,10';preg_match_all('/[a-z]+/i', $Str, $Aarray);$Aarray = $Aarray[0];preg_match_all('/[0-9]+/', $Str, $Barray);$Barray = $Barray[0];$Carray = array_combine($Aarray, $Barray);print_r($Carray);
------解决方案--------------------
11文 你又来鸟 我只想到 explode
$str = 'a,100,b,32,c,10';$arr = explode(',',$str);for($i = 0 ; $i------解决方案--------------------
来一个另类的
$s = 'a,100,b,32,c,10';preg_replace('/(\w+),([^,]+)/se', '$ar[$1]=$2', $s);print_r($ar);