我的字符串为
SportId : 56,GroundType : Public,SelectArea : 10,Cost : 3000-4000 ,Size : 7 * 7
爆炸时此数组输出为
Array
(
[0] => SportId : 56
[1] => GroundType : Public
[2] => SelectArea : 10
[3] => Cost : 3000-4000
[4] => Size : 7 * 7
)
我希望关联数组中的输出为
Array
(
['SportId'] => 56
['GroundType'] => Public
['SelectArea'] => 10
['Cost'] => 3000-4000
['Size'] => 7 * 7
)
答案 0 :(得分:0)
这应该做:
<?php
$info = "SportId : 56,GroundType : Public,SelectArea : 10,Cost : 3000-4000 ,Size : 7 * 7";
$arrInfo = explode(",",$info);
$newArray = [];
foreach($arrInfo as $item) {
$values = explode(":",$item);
$newArray[$values[0]] = $values[1];
}
print_r($newArray);