私は文字列を持っています
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);
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加