'explode array into associative array which already exploded in php [duplicate]

I have string as

SportId : 56,GroundType : Public,SelectArea : 10,Cost : 3000-4000 ,Size : 7 * 7

when explode this array output is

Array
(
    [0] => SportId : 56
    [1] => GroundType : Public
    [2] => SelectArea : 10
    [3] => Cost : 3000-4000 
    [4] => Size : 7 * 7
)

I want output in associative array as

 Array
(
    ['SportId'] => 56
    ['GroundType'] => Public
    ['SelectArea'] => 10
    ['Cost'] => 3000-4000 
    ['Size'] => 7 * 7
)


Solution 1:[1]

This should do:

<?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);

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 deChristo