多次元配列に対する 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 />