2013-03-04 54 views

回答

5

使用正則表達式來獲得所需的值,然後組合數組來獲得關聯數組。例如:

$str = 'p10s2z1234'; 

preg_match_all('/([a-z]+)(\d+)/', $str, $matches); //handles only lower case chars. feel free to extend regex 

print_r(array_combine($matches[1], $matches[2])); 
+0

謝謝,它非常有用 – DuyHung 2013-03-04 08:14:22

0

我說你應該把它P,10,S 2,Z,1234和爆炸()

$測試=「P 10,S,2,Z ,1234" ; $ pieces = explode(「,」,$ test);

從那裏把它們放到一個數組中。