- var_export: documentation ( source)
- explode: documentation ( source)
<?php
$array = [
2 => 'first=1',
3 => 'second=2',
4 => 'third=',
5 => 'first=4',
9 => 'second=3',
];
$result = [];
foreach ($array as $string) {
[$key, $value] = explode('=', $string, 2);
if (!isset($entry) || isset($entry[$key])) {
unset($entry);
$result[] = &$entry;
}
$entry[$key] = $value;
}
var_export($result);