array("msg1"=>"asdasd","msg2"=>"dasdsa"));/*----------如何将一个数据添加到数组中,使数组输出如下---------------------*//* &"/> array("msg1"=>"asdasd","msg2"=>"dasdsa"));/*----------如何将一个数据添加到数组中,使数组输出如下---------------------*//* &">
Home >Backend Development >PHP Tutorial >php 对多维数组的操作,该怎么解决
php 对多维数组的操作
我想将数据循环插入多维数组,请问该怎么做?
代码如下:
<br />$a=array("date"=>array<br />(<br />"msg1"=>"asdasd",<br />"msg2"=>"dasdsa")<br />);<br />/*----------如何将一个数据添加到数组中,使数组输出如下---------------------*/<br />/* Array ( [date] => Array ( [msg1] => asdasd [msg2] => dasdsa[msg3] => dasdsa[msg4] => dasdsa ) ) */<br />
<br />$a=array("date"=>array("msg1"=>"asdasd","msg2"=>"dasdsa"));<br />array_push($a['date'],array('msg3'=>'tel'));<br />print_r($a);<br />
<br />$a=array();<br />foreach($data as $k=>$v){<br /> $a['date']['msg'.$k]=$v;<br />}<br />print_r($a);<br />
$a=array("date"=>array("msg1"=>"asdasd","msg2"=>"dasdsa"));<br />$a['date']['msg3'] = 'tel';<br />print_r($a);
Array<br />(<br /> [date] => Array<br /> (<br /> [msg1] => asdasd<br /> [msg2] => dasdsa<br /> [msg3] => tel<br /> )<br /><br />)<br /><br />
$a=array("date"=>array("msg1"=>"asdasd","msg2"=>"dasdsa"));<br />$a['date']['msg3'] = 'tel';<br />print_r($a);
<br />Array<br />(<br /> [date] => Array<br /> (<br /> [msg1] => asdasd<br /> [msg2] => dasdsa<br /> [msg3] => tel<br /> )<br /> <br />)<br />
$a=array("date"=>array("msg1"=>"asdasd","msg2"=>"dasdsa"));<br />$a = array_merge_recursive($a, array('date' => array('msg3'=>'tel')));<br />print_r($a);
Array<br />(<br /> [date] => Array<br /> (<br /> [msg1] => asdasd<br /> [msg2] => dasdsa<br /> [msg3] => tel<br /> )<br /><br />)<br /><br />