2024-09-18 00:48:10
$a = 'key1=value1$key2=value2$key3=value3$key4=value4';
$temparr = explode('$', $a);
foreach ($temparr as $value) {
$temp = explode('=', $value);
$arr[$temp[0]] = $temp[1];
}
print_r($arr);
将字符串按"$"分割转数组
Array
(
[0] => key1=value1
[1] => key2=value2
[2] => key3=value3
[3] => key4=value4
)
将上面数组的每个元素按"="分割转数组, $temp[0]就是key, $temp[1]就是value
然后将key和value同时放到arr新的数组里面结果就出来了
Array
(
[key1] => value1
[key2] => value2
[key3] => value3
[key4] => value4
)