PHP如何动态为多维数组的子数组分别添加元素
程序员文章站
2022-05-16 18:22:27
...
PHP如何动态为多维数组的子数组分别添加元素,如下:
问题:
问题:
$a=array(0=>array("name"=>"a","mail"=>"b"),1=>array("name"=>"d","mail"=>"e"))
怎样可以变成array(0=>array("name"=>"a","mail"=>"b",tel=>"k"),1=>array("name"=>"d","mail"=>"e" tel=>"e"))
方法$a=array(0=>array("name"=>"a","mail"=>"b"),1=>array("name"=>"d","mail"=>"e"));
function addkey(&$val, $key, $param)
{
$val[$param['key']] = $param['val'];
}
array_walk($a,'addkey',array('key'=>'tel', 'val'=>'123'));
print_r($a);
AD:真正免费,域名+虚机+企业邮箱=0元
下一篇: 对于分表的靠山查询