我们可以在php中为相同的键设置多个值的关联数组吗?
例如: -
array[key1] => value1, value2, value3
array[key2] => value4, value5, value6
答案 0 :(得分:3)
是:
array[key1] => array(value1, value2, value3)
array[key2] => array(value4, value5, value6)
您还可以在关联数组中使用关联数组:
array[key1] => array(key => value1, key => value2, key => value3)
array[key2] => array(key => value4, key => value5, key => value6)
答案 1 :(得分:1)
是的,你可以:
$myvar = array ("key_name" => array("tom", "an", "bob"), "key_age" => array("1", "10", "12");
然后到达那些:
$myvar['key_name'][0];
$myvar['key_age'][0];