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) //} $new[$v['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[$v2]["count"]=0;} }print_r($new);die; //} foreach ($new as $k => $v){ $data[]=array("count"=>$v,"date"=>$k); } /*foreach($arr as $k2 =>$v2 ){foreach($date as $k =>$v ){ if(!array_key_exists($v,$tt)){ $arr[]=array("count"=>0,"date"=>$v); } } }*/ usort($data, function($a, $b) { if($a['date'] == $b['date']) return 0; return $a['date'] > $b['date'] ? 1 : -1; }); print_r($data);die; //对应$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.3.0 - 7.1.0
Array ( [2014-04-16] => Array ( [count] => 10 [date] => 2014-04-16 ) [2014-04-18] => Array ( [count] => 50 [date] => 2014-04-18 ) [2014-04-20] => Array ( [count] => 80 [date] => 2014-04-20 ) ) Array ( [2014-04-16] => Array ( [count] => 10 [date] => 2014-04-16 ) [2014-04-18] => Array ( [count] => 50 [date] => 2014-04-18 ) [2014-04-20] => Array ( [count] => 80 [date] => 2014-04-20 ) [2014-04-17] => Array ( [count] => 0 ) [2014-04-19] => Array ( [count] => 0 ) )
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.2.17
Parse error: syntax error, unexpected T_FUNCTION in /in/eWVvo on line 37
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_FUNCTION in /in/eWVvo on line 37
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/eWVvo on line 37
Process exited with code 255.