codepad
[
create a new paste
]
login
|
about
Language:
C
C++
D
Haskell
Lua
OCaml
PHP
Perl
Plain Text
Python
Ruby
Scheme
Tcl
<?php $string = '1-350,9-390.99'; // first, split the string into an array of pairs $output = explode(',', $string); function split_pairs ($str) { return explode('-', $str, 2); } $output = array_map(split_pairs, $output); // then transpose it to get two arrays, one for keys and one for values array_unshift($output, null); $output = call_user_func_array(array_map, $output); // and finally combine them into one $output = array_combine($output[0], $output[1]); var_export($output);
Private
[
?
]
Run code
Submit