数组推送与数组关联?

时间:2011-05-13 13:09:02

标签: php multidimensional-array

$row_properties = array(
                         "Header 11"=>array("width"=>20,"align"=>'C',"color"=>array(100,220,255),"text_color"=>array(220,50,50)),
                         "Header 12"=>array("width"=>20,"align"=>'C',"color"=>array(100,220,255),"text_color"=>array(220,50,50) )

);

如何推送值

"Header 13"=>array("width"=>20,"align"=>'C',"color"=>array(100,220,255) ,"text_color"=>array(220,50,50)),
"Header 14"=>array("width"=>20,"align"=>'C',"color"=>array(100,220,255) ,"text_color"=>array(220,50,50)),

所以它会得到结果

$row_properties = array(
"Header  11"=>array("width"=>20,"align"=>'C',"color"=>array(100,220,255),"text_color"=>array(220,50,50)),
"Header12"=>array("width"=>20,"align"=>'C',"color"=>array(100,220,255),"text_color"=>array(220,50,50),
"Header 13"=>array("width"=>20,"align"=>'C',"color"=>array(100,220,255) ,"text_color"=>array(220,50,50)),
"Header 14"=>array("width"=>20,"align"=>'C',"color"=>array(100,220,255) ,"text_color"=>array(220,50,50))
                  )
              );

3 个答案:

答案 0 :(得分:1)

简单

$row_properties["Header 13"] = array("width"=>20,"align"=>'C',"color"=>array(100,220,255) ,"text_color"=>array(220,50,50));

答案 1 :(得分:1)

尝试了array_merge()功能?

答案 2 :(得分:0)

也许是这样的:

$push_vals = array(
    "Header 13"=>array("width"=>20,"align"=>'C',"color"=>array(100,220,255) ,"text_color"=>array(220,50,50)),
    "Header 14"=>array("width"=>20,"align"=>'C',"color"=>array(100,220,255) ,"text_color"=>array(220,50,50)),
);

$arr = array(
     "Header 11"=>array("width"=>20,"align"=>'C',"color"=>array(100,220,255),"text_color"=>array(220,50,50)),
     "Header 12"=>array("width"=>20,"align"=>'C',"color"=>array(100,220,255),"text_color"=>array(220,50,50)
);

foreach ($push_vals as $key=>$value){
    if ( isset($arr[$key]) ) 
        $arr = array_merge($arr[$key], $push_vals[$key]);
    else
        $arr[$key] = $push_vals[$key];

}

更新

durrr array_merge_recursive