Php does not have to directly split the string into keyvalue form. Is there such a function that converts a, 100, B, 32, c, 10 to array (& nbsp; a & gt; 100, & nbsp; B & gt; 32, & nbsp; c & gt; 10) There are no direct functions. Otherwise, I can only str_split and then change the o (bytes □splits) cyclically) o ------ solution ------------ php has no function that directly splits the string into key values.
Is there such a function that calls a, 100, B, 32, c, 10?
To array (
& Apos; a & apos; = & apos; 100 & apos,
'B' => 32,
'C' => 10
)
There are no direct functions available
Otherwise, I can only split the str_split and then change the cycle to o (else □else) o.
------ Solution --------------------
PHP code
$ 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 )*/
------ Solution --------------------
No direct functions, and a lot of disgusting code...
PHP code
$ 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 );
------ Solution --------------------
11 You Come Again, I only want to explode
PHP code
$ Str = 'a, 100, B, 32, c, 10'; $ arr = explode (',', $ str); for ($ I = 0; $ I
------ Solution --------------------
Come to an alternative
PHP code
$s = 'a,100,b,32,c,10';preg_replace('/(\w+),([^,]+)/se', '$ar[$1]=$2', $s);print_r($ar);