PHP - split String in Key/Value pairs
问题 I have a string like this: key=value, key2=value2 and I would like to parse it into something like this: array( \"key\" => \"value\", \"key2\" => \"value2\" ) I could do something like $parts = explode(\",\", $string) $parts = array_map(\"trim\", $parts); foreach($parts as $currentPart) { list($key, $value) = explode(\"=\", $currentPart); $keyValues[$key] = $value; } But this seems ridiciulous. There must be some way to do this smarter with PHP right? 回答1: If you don't mind using regex ...