php有没得 直接把字符串分割为key value形式的函数
有没有这样的函数把 a,100,b,32,c,10
变成 array(
'a'=>100,
'b'=>32,
'c'=>10
)
有没得直接的函数
否则我只能str_split 然后循环变了 o(╯□╰)o
------解决方案--------------------
$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 '<pre class="brush:php;toolbar:false;">';print_r($res);echo '$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);<br><font color="#e78608">------解决方案--------------------</font><br>11文 你又来鸟 我只想到 explode<br>$str = 'a,100,b,32,c,10';$arr = explode(',',$str);for($i = 0 ; $i <count if></count><font color="#e78608">------解决方案--------------------</font><br>来一个另类的<br>$s = 'a,100,b,32,c,10';preg_replace('/(\w+),([^,]+)/se', '$ar[$1]=$2', $s);print_r($ar);<div class="clear"></div>
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号