我是PHP的新手。但我试图在一个数组中的一个键中分配多个值,并且我遇到了问题。我做错了什么?
$skill_groups = array(
'combat' => 'Attack', 'Defence', 'Strength', '', 'Ranged', 'Magic',
'gathering' => 'Mining', 'Woodcutting', 'Fishing', 'Hunter', 'Farming', 'Divination',
'artisan' => 'Smithing', 'Cooking', 'Runecrafting', 'Crafting', 'Firemaking', 'Herblore', 'Fletching', 'Construction',
'support' => 'Dungeoneering', 'Thieving', 'Agility', 'Slayer', 'Prayer', 'Constitution'
);
答案 0 :(得分:3)
您想要创建多维数组。正确的语法就像
$skill_groups = array(
'combat' => array('Attack', 'Defence', 'Strength', '', 'Ranged', 'Magic'),
'gathering' => array('Mining', 'Woodcutting', 'Fishing', 'Hunter', 'Farming', 'Divination'),
'artisan' => array('Smithing', 'Cooking', 'Runecrafting', 'Crafting', 'Firemaking', 'Herblore', 'Fletching', 'Construction'),
'support' => array('Dungeoneering', 'Thieving', 'Agility', 'Slayer', 'Prayer', 'Constitution'));
并且访问元素如下:
print_r($skill_groups['combat']); // something like array([0] => 'Attack', [1] => 'Defence', [2] => 'Strength', [3] => '', [4] => 'Ranged', [5] => 'Magic')
echo $skill_groups['combat'][0]; // 'Attack'