- array_chunk: documentation ( source)
- var_export: documentation ( source)
- explode: documentation ( source)
<?php
$str = 'key1\value1\key2\value2\key3\value3\key4\value4\key5\value5';
$result = [];
foreach (array_chunk(explode('\\', $str), 2) as [$key, $val]) {
$result[$key] = $val;
}
var_export($result);