开发者

Array Push with associative to array?

开发者 https://www.devze.com 2023-03-06 04:24 出处:网络
$row_properties = array( \"Header 11\"=>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)),
                         "Header 12"=>array("width"=>20,"align"=>'C',"color"=>array(100,220,255),"text_color"=>array(220,50,50) )

);

How I can Push the values

"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)),

SO it will got the result

$row_properties = array(
"Header  11"=>array("width"=>20,"align"=>'C',"color"=>array(100,220,255),"text_color"开发者_如何学C=>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))
                  )
              );


Simple

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


Tried the array_merge() function?


Maybe something like this:

$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];

}

Update

durrr array_merge_recursive

0

精彩评论

暂无评论...
验证码 换一张
取 消