<?php $string = 'key1=>value1,key2=>value2,key3=>value3'; $pairs = explode(',', $string); $data = array(); foreach ($pairs as $pair) { list($key, $value) = explode('=>', $pair); $data[$key] = $value; } var_dump($data);
Standard input is empty
array(3) { ["key1"]=> string(6) "value1" ["key2"]=> string(6) "value2" ["key3"]=> string(6) "value3" }
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!