如何使数组键成为PHP数组

时间:2017-08-19 10:24:06

标签: php arrays json

我将数据存储到这样的数组中,该数组位于三个嵌套循环内(循环省略):

$teamDetails[$k] = array(
    'side' => $json['data'][$i]['rosters'][$k]['side'],
    'gold' => $json['data'][$i]['rosters'][$k]['gold'],
    'aces' => $json['data'][$i]['rosters'][$k]['aces_earned'],
    'herokills' => $json['data'][$i]['rosters'][$k]['hero_kills'],
    'winner' => translateGame($json['data'][$i]['rosters'][$k]['winner']),
    'participants'[$j] => array(
         'work' => 'it worked',
     )
 );

如何让参与者'索引来自$ j的数组?

1 个答案:

答案 0 :(得分:5)

那很简单

$teamDetails[$k] = array(
    'side' => $json['data'][$i]['rosters'][$k]['side'],
    'gold' => $json['data'][$i]['rosters'][$k]['gold'],
    'aces' => $json['data'][$i]['rosters'][$k]['aces_earned'],
    'herokills' => $json['data'][$i]['rosters'][$k]['hero_kills'],
    'winner' => translateGame($json['data'][$i]['rosters'][$k]['winner']),
    'participants' => array(
        $j => array(
         'work' => 'it worked',
     ))
);