[ create a new paste ] login | about

Link: http://codepad.org/7oA8CeCB    [ raw code | output | fork ]

PHP, pasted on Jan 3:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<?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);


Output:
1
2
3
4
array (
  1 => '350',
  9 => '390.99',
)


Create a new paste based on this one


Comments: