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($date as $k =>$v ){ foreach($arr as $k2 =>$v2 ){ 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 - 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-16 ) [5] => Array ( [count] => 0 [date] => 2014-04-16 ) [6] => Array ( [count] => 0 [date] => 2014-04-17 ) [7] => Array ( [count] => 0 [date] => 2014-04-17 ) [8] => Array ( [count] => 0 [date] => 2014-04-17 ) [9] => Array ( [count] => 0 [date] => 2014-04-17 ) [10] => Array ( [count] => 0 [date] => 2014-04-17 ) [11] => Array ( [count] => 0 [date] => 2014-04-17 ) [12] => Array ( [count] => 0 [date] => 2014-04-18 ) [13] => Array ( [count] => 0 [date] => 2014-04-18 ) [14] => Array ( [count] => 0 [date] => 2014-04-18 ) [15] => Array ( [count] => 0 [date] => 2014-04-18 ) [16] => Array ( [count] => 0 [date] => 2014-04-18 ) [17] => Array ( [count] => 0 [date] => 2014-04-18 ) [18] => Array ( [count] => 0 [date] => 2014-04-18 ) [19] => Array ( [count] => 0 [date] => 2014-04-18 ) [20] => Array ( [count] => 0 [date] => 2014-04-18 ) [21] => Array ( [count] => 0 [date] => 2014-04-18 ) [22] => Array ( [count] => 0 [date] => 2014-04-18 ) [23] => Array ( [count] => 0 [date] => 2014-04-18 ) [24] => Array ( [count] => 0 [date] => 2014-04-19 ) [25] => Array ( [count] => 0 [date] => 2014-04-19 ) [26] => Array ( [count] => 0 [date] => 2014-04-19 ) [27] => Array ( [count] => 0 [date] => 2014-04-19 ) [28] => Array ( [count] => 0 [date] => 2014-04-19 ) [29] => Array ( [count] => 0 [date] => 2014-04-19 ) [30] => Array ( [count] => 0 [date] => 2014-04-19 ) [31] => Array ( [count] => 0 [date] => 2014-04-19 ) [32] => Array ( [count] => 0 [date] => 2014-04-19 ) [33] => Array ( [count] => 0 [date] => 2014-04-19 ) [34] => Array ( [count] => 0 [date] => 2014-04-19 ) [35] => Array ( [count] => 0 [date] => 2014-04-19 ) [36] => Array ( [count] => 0 [date] => 2014-04-19 ) [37] => Array ( [count] => 0 [date] => 2014-04-19 ) [38] => Array ( [count] => 0 [date] => 2014-04-19 ) [39] => Array ( [count] => 0 [date] => 2014-04-19 ) [40] => Array ( [count] => 0 [date] => 2014-04-19 ) [41] => Array ( [count] => 0 [date] => 2014-04-19 ) [42] => Array ( [count] => 0 [date] => 2014-04-19 ) [43] => Array ( [count] => 0 [date] => 2014-04-19 ) [44] => Array ( [count] => 0 [date] => 2014-04-19 ) [45] => Array ( [count] => 0 [date] => 2014-04-19 ) [46] => Array ( [count] => 0 [date] => 2014-04-19 ) [47] => Array ( [count] => 0 [date] => 2014-04-19 ) [48] => Array ( [count] => 0 [date] => 2014-04-20 ) [49] => Array ( [count] => 0 [date] => 2014-04-20 ) [50] => Array ( [count] => 0 [date] => 2014-04-20 ) [51] => Array ( [count] => 0 [date] => 2014-04-20 ) [52] => Array ( [count] => 0 [date] => 2014-04-20 ) [53] => Array ( [count] => 0 [date] => 2014-04-20 ) [54] => Array ( [count] => 0 [date] => 2014-04-20 ) [55] => Array ( [count] => 0 [date] => 2014-04-20 ) [56] => Array ( [count] => 0 [date] => 2014-04-20 ) [57] => Array ( [count] => 0 [date] => 2014-04-20 ) [58] => Array ( [count] => 0 [date] => 2014-04-20 ) [59] => Array ( [count] => 0 [date] => 2014-04-20 ) [60] => Array ( [count] => 0 [date] => 2014-04-20 ) [61] => Array ( [count] => 0 [date] => 2014-04-20 ) [62] => Array ( [count] => 0 [date] => 2014-04-20 ) [63] => Array ( [count] => 0 [date] => 2014-04-20 ) [64] => Array ( [count] => 0 [date] => 2014-04-20 ) [65] => Array ( [count] => 0 [date] => 2014-04-20 ) [66] => Array ( [count] => 0 [date] => 2014-04-20 ) [67] => Array ( [count] => 0 [date] => 2014-04-20 ) [68] => Array ( [count] => 0 [date] => 2014-04-20 ) [69] => Array ( [count] => 0 [date] => 2014-04-20 ) [70] => Array ( [count] => 0 [date] => 2014-04-20 ) [71] => Array ( [count] => 0 [date] => 2014-04-20 ) [72] => Array ( [count] => 0 [date] => 2014-04-20 ) [73] => Array ( [count] => 0 [date] => 2014-04-20 ) [74] => Array ( [count] => 0 [date] => 2014-04-20 ) [75] => Array ( [count] => 0 [date] => 2014-04-20 ) [76] => Array ( [count] => 0 [date] => 2014-04-20 ) [77] => Array ( [count] => 0 [date] => 2014-04-20 ) [78] => Array ( [count] => 0 [date] => 2014-04-20 ) [79] => Array ( [count] => 0 [date] => 2014-04-20 ) [80] => Array ( [count] => 0 [date] => 2014-04-20 ) [81] => Array ( [count] => 0 [date] => 2014-04-20 ) [82] => Array ( [count] => 0 [date] => 2014-04-20 ) [83] => Array ( [count] => 0 [date] => 2014-04-20 ) [84] => Array ( [count] => 0 [date] => 2014-04-20 ) [85] => Array ( [count] => 0 [date] => 2014-04-20 ) [86] => Array ( [count] => 0 [date] => 2014-04-20 ) [87] => Array ( [count] => 0 [date] => 2014-04-20 ) [88] => Array ( [count] => 0 [date] => 2014-04-20 ) [89] => Array ( [count] => 0 [date] => 2014-04-20 ) [90] => Array ( [count] => 0 [date] => 2014-04-20 ) [91] => Array ( [count] => 0 [date] => 2014-04-20 ) [92] => Array ( [count] => 0 [date] => 2014-04-20 ) [93] => Array ( [count] => 0 [date] => 2014-04-20 ) [94] => Array ( [count] => 0 [date] => 2014-04-20 ) [95] => Array ( [count] => 0 [date] => 2014-04-20 ) )