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 $k =>$v ){ //if(!array_key_exists($v['date'],$date)){ // $arr[]=array("count"=>0,"date"=>$date) //} $tt[]=$v['date']; } foreach($arr as $k2 =>$v2 ){foreach($date as $k =>$v ){ if(!array_key_exists($v,$tt)){ $arr[]=array("count"=>0,"date"=>$v); } } } print_r($arr); //对应$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 - 5.6.28, hhvm-3.10.0 - 3.13.2, 7.0.0 - 7.1.0
Array ( [0] => Array ( [count] => 10 [date] => 2014-04-16 ) [1] => Array ( [count] => 50 [date] => 2014-04-18 ) [2] => Array ( [count] => 80 [date] => 2014-04-20 ) [3] => Array ( [count] => 0 [date] => 2014-04-16 ) [4] => Array ( [count] => 0 [date] => 2014-04-17 ) [5] => Array ( [count] => 0 [date] => 2014-04-18 ) [6] => Array ( [count] => 0 [date] => 2014-04-19 ) [7] => Array ( [count] => 0 [date] => 2014-04-20 ) [8] => Array ( [count] => 0 [date] => 2014-04-16 ) [9] => Array ( [count] => 0 [date] => 2014-04-17 ) [10] => Array ( [count] => 0 [date] => 2014-04-18 ) [11] => Array ( [count] => 0 [date] => 2014-04-19 ) [12] => Array ( [count] => 0 [date] => 2014-04-20 ) [13] => Array ( [count] => 0 [date] => 2014-04-16 ) [14] => Array ( [count] => 0 [date] => 2014-04-17 ) [15] => Array ( [count] => 0 [date] => 2014-04-18 ) [16] => Array ( [count] => 0 [date] => 2014-04-19 ) [17] => Array ( [count] => 0 [date] => 2014-04-20 ) )