3v4l.org

run code in 300+ PHP versions simultaneously
<?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") );
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 9
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 9
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 9
2 jumps found. (Code = 77) Position 1 = 14, Position 2 = 23
Branch analysis from position: 14
2 jumps found. (Code = 78) Position 1 = 15, Position 2 = 23
Branch analysis from position: 15
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 22
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
Branch analysis from position: 22
Branch analysis from position: 23
1 jumps found. (Code = 79) Position 1 = -2
Branch analysis from position: 23
Branch analysis from position: 9
filename:       /in/eWVvo
function name:  (null)
number of ops:  48
compiled vars:  !0 = $arr, !1 = $date, !2 = $v, !3 = $k, !4 = $new, !5 = $v2, !6 = $k2, !7 = $data
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, <array>
   12     1        ASSIGN                                                   !1, <array>
   14     2      > FE_RESET_R                                       $10     !0, ->9
          3    > > FE_FETCH_R                                       ~11     $10, !2, ->9
          4    >   ASSIGN                                                   !3, ~11
   18     5        FETCH_DIM_R                                      ~13     !2, 'date'
          6        ASSIGN_DIM                                               !4, ~13
          7        OP_DATA                                                  !2
   14     8      > JMP                                                      ->3
          9    >   FE_FREE                                                  $10
   20    10        INIT_FCALL                                               'print_r'
         11        SEND_VAR                                                 !4
         12        DO_ICALL                                                 
   23    13      > FE_RESET_R                                       $16     !1, ->23
         14    > > FE_FETCH_R                                       ~17     $16, !5, ->23
         15    >   ASSIGN                                                   !6, ~17
   24    16        ARRAY_KEY_EXISTS                                 ~19     !5, !4
         17        BOOL_NOT                                         ~20     ~19
         18      > JMPZ                                                     ~20, ->22
         19    >   FETCH_DIM_W                                      $21     !4, !5
         20        ASSIGN_DIM                                               $21, 'count'
         21        OP_DATA                                                  0
   23    22    > > JMP                                                      ->14
         23    >   FE_FREE                                                  $16
   25    24        INIT_FCALL                                               'print_r'
         25        SEND_VAR                                                 !4
         26        DO_ICALL                                                 
         27      > EXIT                                                     
   27    28*       FE_RESET_R                                       $24     !4, ->36
         29*       FE_FETCH_R                                       ~25     $24, !2, ->36
         30*       ASSIGN                                                   !3, ~25
   28    31*       INIT_ARRAY                                       ~28     !2, 'count'
         32*       ADD_ARRAY_ELEMENT                                ~28     !3, 'date'
         33*       ASSIGN_DIM                                               !7
         34*       OP_DATA                                                  ~28
   27    35*       JMP                                                      ->29
         36*       FE_FREE                                                  $24
   37    37*       INIT_FCALL                                               'usort'
         38*       SEND_REF                                                 !7
         39*       DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FeWVvo%3A37%240'
   40    40*       SEND_VAL                                                 ~29
         41*       DO_ICALL                                                 
   41    42*       INIT_FCALL                                               'print_r'
         43*       SEND_VAR                                                 !7
         44*       DO_ICALL                                                 
         45*       EXIT                                                     
   45    46*       ASSIGN                                                   !0, <array>
   56    47*     > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2FeWVvo%3A37%240:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 7
Branch analysis from position: 6
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 13
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/eWVvo
function name:  {closure}
number of ops:  16
compiled vars:  !0 = $a, !1 = $b
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   37     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   38     2        FETCH_DIM_R                                      ~2      !0, 'date'
          3        FETCH_DIM_R                                      ~3      !1, 'date'
          4        IS_EQUAL                                                 ~2, ~3
          5      > JMPZ                                                     ~4, ->7
          6    > > RETURN                                                   0
   39     7    >   FETCH_DIM_R                                      ~5      !0, 'date'
          8        FETCH_DIM_R                                      ~6      !1, 'date'
          9        IS_SMALLER                                               ~6, ~5
         10      > JMPZ                                                     ~7, ->13
         11    >   QM_ASSIGN                                        ~8      1
         12      > JMP                                                      ->14
         13    >   QM_ASSIGN                                        ~8      -1
         14    > > RETURN                                                   ~8
   40    15*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FeWVvo%3A37%240

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
157.22 ms | 1400 KiB | 17 Q