在PHP Array index addition - different levels
中有没有办法让数组键名称为'加权','未加权','weighted_sum','unweighted_sum'而不是数组索引号?
所以在所需的输出而不是[0] =>数组,[1] =>数组,[2] => , [3] =>
有没有办法获得'加权'=>数组,'unweighted'=>数组,'weighted_sum'=> ,'unweighted_sum'=>
TIA 雅
答案 0 :(得分:0)
$keys = array_keys($m_aggregate);
$tot_aggregate = sum($m_aggregate, $f_aggregate);
$tot_aggregate = array_combine($keys, $tot_aggregate);
答案 1 :(得分:-3)
$array=array(
'weighted' => 'x',
'unweighted' => 'y',
'weighted_sum' => 'z'
);
echo $array['weighted'];
多维数组 http://webcheatsheet.com/PHP/multidimensional_arrays.php