-4

次の文字列の配列を作成するにはどうすればよいですか:

$scope = "calls:full,departments:full,employees:full,companies:full,stages:full,accounts:full,resources:full,products:full,reports:full";

次のように表します。

$scope = array(
    'calls' => full,
    'departments' => full,
    'employees' => full,
    .... and so on >>
);
4

3 に答える 3

5
$scope = "calls:full,departments:full,employees:full,companies:full,stages:full,accounts:full,resources:full,products:full,reports:full";
$parts = explode(',', $scope);
$arr = array();

foreach($parts as $val)   {
    list($key, $value) = explode(':', $val);
    $arr[$key] = $value; 
}
于 2013-09-03T13:23:16.590 に答える
0
$scope = "calls:full,departments:full,employees:full,companies:full,stages:full,accounts:full,resources:full,products:full,reports:full";
foreach(explode(",", $scope) as $v){ 
  $temp = explode(":", $v); 
  $array[$temp[0]]=$temp[1];
}
print_r($array);
于 2013-09-03T13:23:22.477 に答える