fork(146) download
  1. <?php
  2. $string = '1-350,9-390.99';
  3. $array = explode(',',$string);
  4. $new_array = array();
  5.  
  6. array_walk($array,'walk', &$new_array);
  7.  
  8. function walk($val, $key, $new_array){
  9. $nums = explode('-',$val);
  10. $new_array[$nums[0]] = $nums[1];
  11. }
  12. print_r($new_array);
  13.  
  14. ?>
Success #stdin #stdout 0.02s 13112KB
stdin
Standard input is empty
stdout
Array
(
    [1] => 350
    [9] => 390.99
)