-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
<?php
$a = "calls:full,departments:full,employees:full,companies:full,stages:full,accounts:full,resources:full,products:full,reports:full";
$exploded=array();
$exploded=explode(",",$a);

$new=array();
foreach($exploded as $explode){
    $explode=explode(":",$explode);
    //print_r($explode);
    $new[$explode[0]]=$explode[1];
}
print_r($new);
?>
于 2013-09-03T13:26:44.963 回答
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 回答