输入:
$this->request->get(['opt']) = '337:230,323:112';
我当前的代码:
$option = explode(",", $this->request->get['opt']);
foreach ($option as $key => $value) {
echo $value . "<br>";
}
我的结果:
337:230
323:112
问题: 如何将上述数据分离成关联数组?
期望的结果:
[
337 => 230,
323 => 112,
]
看起来你只需要在冒号上再次爆炸,所以也许像this?
<?php
$opt = '337:230,323:112';
$option = explode(",", $opt);
foreach ($option as $pair) {
list(key, $value) = explode(':', $pair);
$array[$key] = $value;
}
print_r($array);
Array ( [337] => 230 [323] => 112 )