3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $arr=array( array("count"=>10,"date"=>"2014-04-16"), array("count"=>50,"date"=>"2014-04-18"), array("count"=>80,"date"=>"2014-04-20") ); $date =array("2014-04-16","2014-04-17","2014-04-18","2014-04-19","2014-04-20"); foreach($arr as $val){ $new_arr[$val['date']] = $val['count']; } foreach($date as $key => $val){ $result[$key]['count'] = isset($new_arr[$val]) ? $new_arr[$val] : 0; $result[$key]['date'] = $val; } print_r($result); //对应$date所有日期转换为 $arr=array( array("count"=>10,"date"=>"2014-04-16"), array("count"=>0,"date"=>"2014-04-17"), array("count"=>50,"date"=>"2014-04-18"), array("count"=>0,"date"=>"2014-04-19"), array("count"=>80,"date"=>"2014-04-20"), );
Output for 4.3.0 - 7.1.0
Array ( [0] => Array ( [count] => 10 [date] => 2014-04-16 ) [1] => Array ( [count] => 0 [date] => 2014-04-17 ) [2] => Array ( [count] => 50 [date] => 2014-04-18 ) [3] => Array ( [count] => 0 [date] => 2014-04-19 ) [4] => Array ( [count] => 80 [date] => 2014-04-20 ) )