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'];$cc[]=$v['count']; $new['date']=$v["count"]; }print_r($new); print_r(array_combine($date,$new)); //foreach($new as $k =>$v){ foreach($date as $k2 =>$v2 ){ if(!array_key_exists($v2,$new)){$new[$k2]=0;} }print_r($new); //} 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 5.2.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
Array ( [date] => 80 ) Warning: array_combine(): Both parameters should have an equal number of elements in /in/WO4Tm on line 22 Array ( [date] => 80 [0] => 0 [1] => 0 [2] => 0 [3] => 0 [4] => 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 ) )
Output for 5.0.0 - 5.1.6
Array ( [date] => 80 ) Warning: array_combine(): Both parameters should have equal number of elements in /in/WO4Tm on line 22 Array ( [date] => 80 [0] => 0 [1] => 0 [2] => 0 [3] => 0 [4] => 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 ) )
Output for 4.4.5 - 4.4.9
Array ( [date] => 80 ) Fatal error: Call to undefined function: array_combine() in /in/WO4Tm on line 22
Process exited with code 255.
Output for 4.3.2 - 4.4.4
Array ( [date] => 80 ) Fatal error: Call to undefined function: array_combine() in /in/WO4Tm on line 22
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Array ( [date] => 80 ) Fatal error: Call to undefined function: array_combine() in /in/WO4Tm on line 22