将数组分解为已在 php 中分解的关联数组
explode array into associative array which already exploded in php
我有字符串
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
)
应该这样做:
<?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);
我有字符串
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
)
应该这样做:
<?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);