请教如何在PHP多维数组中筛选出自己想要的数值并输出?
我纠结了好久的一个问题,请大牛赐教!
有这样一个数组
<br />Array( <br />[0] => Array ( <br /> [log_data] => 4 <br /> [log_result] => 0 <br /> [log_time] => 2013-05-08 10:08:40 ) <br />[1] => Array ( <br /> [log_data] => 10018 <br /> [log_result] => 2 <br /> [log_time] => 2013-05-08 10:13:58 ) <br />[2] => Array ( <br /> [log_data] => 10018 <br /> [log_result] => 2 <br /> [log_time] => 2013-05-08 10:14:02 )<br />[3] => Array ( <br /> [log_data] => 10003 <br /> [log_result] => 50 <br /> [log_time] => 2013-05-08 10:18:29 ) <br />)<br />
$ar = Array( <br /> Array ( <br /> 'log_data' => 4,<br /> 'log_result' => 0,<br /> 'log_time' => '2013-05-08 10:08:40'<br /> ), <br /> Array ( <br /> 'log_data' => 10018,<br /> 'log_result' => 2,<br /> 'log_time' => '2013-05-08 10:13:58',<br /> ),<br /> Array ( <br /> 'log_data' => 10018,<br /> 'log_result' => 2,<br /> 'log_time' => '2013-05-08 10:14:02',<br /> ),<br /> Array (<br /> 'log_data' => 10003,<br /> 'log_result' => 50,<br /> 'log_time' => '2013-05-08 10:18:29',<br /> ),<br />);<br />foreach($ar as $item) {<br /> @$res[$item['log_data']][strtok($item['log_time'], ' ')] += $item['log_result'];<br />}<br />print_r($res);<br />
Array<br />(<br /> [4] => Array<br /> (<br /> [2013-05-08] => 0<br /> )<br /><br /> [10018] => Array<br /> (<br /> [2013-05-08] => 4<br /> )<br /><br /> [10003] => Array<br /> (<br /> [2013-05-08] => 50<br /> )<br /><br />)<br /><br />
<br><?php <br />$ar = Array( <br> Array ( <br> 'log_data' => 4,<br> 'log_result' => 0,<br> 'log_time' => '2013-05-08 10:08:40'<br> ), <br> Array ( <br> 'log_data' => 10018,<br> 'log_result' => 2,<br> 'log_time' => '2013-05-08 10:13:58',<br> ),<br> Array ( <br> 'log_data' => 10018,<br> 'log_result' => 2,<br> 'log_time' => '2013-05-08 10:14:02',<br> ),<br> Array (<br> 'log_data' => 10003,<div class="clear"> </div>