3v4l.org

run code in 300+ PHP versions simultaneously
<?php $posts = array( array('post_id' => 7, 'timestamp' => '2014-04-20 20:17:49'), array('post_id' => 6, 'timestamp' => '2014-04-07 20:17:49'), array('post_id' => 5, 'timestamp' => '2014-03-17 20:17:49'), array('post_id' => 4, 'timestamp' => '2014-02-14 20:17:49'), array('post_id' => 3, 'timestamp' => '2014-01-09 20:17:49'), array('post_id' => 2, 'timestamp' => '2013-09-23 20:17:49'), array('post_id' => 1, 'timestamp' => '2012-09-23 20:17:49') ); $today = strtotime(date("Y-m-d")); $week_start = strtotime('last sunday', strtotime('tomorrow')); $month_start = strtotime(date_create(date("Y-m-d"))->modify('first day of this month')->format("Y-m-d")); $year_start = strtotime(date_create(date("Y-m-d"))->modify('first day of january 2014')->format("Y-m-d")); foreach ($posts as $post) { $item = strtotime($post['timestamp']); if ($item >= $today) { // Today echo '<br><br>' . 'Today' . '<br>'; echo $post['post_id'] . '<br>'; } else if (($item <= $today) && ($item >= $week_start)) { // This week echo '<br><br>' . 'This week' . '<br>'; echo $post['post_id'] . '<br>'; } else if (($item <= $week_start) && ($item >= $month_start)) { // This week echo '<br><br>' . 'This month' . '<br>'; echo $post['post_id'] . '<br>'; } else if (($item <= $month_start) && ($item >= $year_start)) { // This week echo '<br><br>' . 'This year' . '<br>'; echo $post['post_id'] . '<br>'; } }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 49, Position 2 = 92
Branch analysis from position: 49
2 jumps found. (Code = 78) Position 1 = 50, Position 2 = 92
Branch analysis from position: 50
2 jumps found. (Code = 43) Position 1 = 57, Position 2 = 62
Branch analysis from position: 57
1 jumps found. (Code = 42) Position 1 = 91
Branch analysis from position: 91
1 jumps found. (Code = 42) Position 1 = 49
Branch analysis from position: 49
Branch analysis from position: 62
2 jumps found. (Code = 46) Position 1 = 64, Position 2 = 66
Branch analysis from position: 64
2 jumps found. (Code = 43) Position 1 = 67, Position 2 = 72
Branch analysis from position: 67
1 jumps found. (Code = 42) Position 1 = 91
Branch analysis from position: 91
Branch analysis from position: 72
2 jumps found. (Code = 46) Position 1 = 74, Position 2 = 76
Branch analysis from position: 74
2 jumps found. (Code = 43) Position 1 = 77, Position 2 = 82
Branch analysis from position: 77
1 jumps found. (Code = 42) Position 1 = 91
Branch analysis from position: 91
Branch analysis from position: 82
2 jumps found. (Code = 46) Position 1 = 84, Position 2 = 86
Branch analysis from position: 84
2 jumps found. (Code = 43) Position 1 = 87, Position 2 = 91
Branch analysis from position: 87
1 jumps found. (Code = 42) Position 1 = 49
Branch analysis from position: 49
Branch analysis from position: 91
Branch analysis from position: 86
Branch analysis from position: 76
Branch analysis from position: 66
Branch analysis from position: 92
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 92
filename:       /in/pCFt6
function name:  (null)
number of ops:  94
compiled vars:  !0 = $posts, !1 = $today, !2 = $week_start, !3 = $month_start, !4 = $year_start, !5 = $post, !6 = $item
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   13     1        INIT_FCALL                                               'strtotime'
          2        INIT_FCALL                                               'date'
          3        SEND_VAL                                                 'Y-m-d'
          4        DO_ICALL                                         $8      
          5        SEND_VAR                                                 $8
          6        DO_ICALL                                         $9      
          7        ASSIGN                                                   !1, $9
   14     8        INIT_FCALL                                               'strtotime'
          9        SEND_VAL                                                 'last+sunday'
         10        INIT_FCALL                                               'strtotime'
         11        SEND_VAL                                                 'tomorrow'
         12        DO_ICALL                                         $11     
         13        SEND_VAR                                                 $11
         14        DO_ICALL                                         $12     
         15        ASSIGN                                                   !2, $12
   15    16        INIT_FCALL                                               'strtotime'
         17        INIT_FCALL                                               'date_create'
         18        INIT_FCALL                                               'date'
         19        SEND_VAL                                                 'Y-m-d'
         20        DO_ICALL                                         $14     
         21        SEND_VAR                                                 $14
         22        DO_ICALL                                         $15     
         23        INIT_METHOD_CALL                                         $15, 'modify'
         24        SEND_VAL_EX                                              'first+day+of+this+month'
         25        DO_FCALL                                      0  $16     
         26        INIT_METHOD_CALL                                         $16, 'format'
         27        SEND_VAL_EX                                              'Y-m-d'
         28        DO_FCALL                                      0  $17     
         29        SEND_VAR                                                 $17
         30        DO_ICALL                                         $18     
         31        ASSIGN                                                   !3, $18
   16    32        INIT_FCALL                                               'strtotime'
         33        INIT_FCALL                                               'date_create'
         34        INIT_FCALL                                               'date'
         35        SEND_VAL                                                 'Y-m-d'
         36        DO_ICALL                                         $20     
         37        SEND_VAR                                                 $20
         38        DO_ICALL                                         $21     
         39        INIT_METHOD_CALL                                         $21, 'modify'
         40        SEND_VAL_EX                                              'first+day+of+january+2014'
         41        DO_FCALL                                      0  $22     
         42        INIT_METHOD_CALL                                         $22, 'format'
         43        SEND_VAL_EX                                              'Y-m-d'
         44        DO_FCALL                                      0  $23     
         45        SEND_VAR                                                 $23
         46        DO_ICALL                                         $24     
         47        ASSIGN                                                   !4, $24
   18    48      > FE_RESET_R                                       $26     !0, ->92
         49    > > FE_FETCH_R                                               $26, !5, ->92
   20    50    >   INIT_FCALL                                               'strtotime'
         51        FETCH_DIM_R                                      ~27     !5, 'timestamp'
         52        SEND_VAL                                                 ~27
         53        DO_ICALL                                         $28     
         54        ASSIGN                                                   !6, $28
   22    55        IS_SMALLER_OR_EQUAL                                      !1, !6
         56      > JMPZ                                                     ~30, ->62
   25    57    >   ECHO                                                     '%3Cbr%3E%3Cbr%3EToday%3Cbr%3E'
   26    58        FETCH_DIM_R                                      ~31     !5, 'post_id'
         59        CONCAT                                           ~32     ~31, '%3Cbr%3E'
         60        ECHO                                                     ~32
         61      > JMP                                                      ->91
   28    62    >   IS_SMALLER_OR_EQUAL                              ~33     !6, !1
         63      > JMPZ_EX                                          ~33     ~33, ->66
         64    >   IS_SMALLER_OR_EQUAL                              ~34     !2, !6
         65        BOOL                                             ~33     ~34
         66    > > JMPZ                                                     ~33, ->72
   31    67    >   ECHO                                                     '%3Cbr%3E%3Cbr%3EThis+week%3Cbr%3E'
   32    68        FETCH_DIM_R                                      ~35     !5, 'post_id'
         69        CONCAT                                           ~36     ~35, '%3Cbr%3E'
         70        ECHO                                                     ~36
         71      > JMP                                                      ->91
   34    72    >   IS_SMALLER_OR_EQUAL                              ~37     !6, !2
         73      > JMPZ_EX                                          ~37     ~37, ->76
         74    >   IS_SMALLER_OR_EQUAL                              ~38     !3, !6
         75        BOOL                                             ~37     ~38
         76    > > JMPZ                                                     ~37, ->82
   37    77    >   ECHO                                                     '%3Cbr%3E%3Cbr%3EThis+month%3Cbr%3E'
   38    78        FETCH_DIM_R                                      ~39     !5, 'post_id'
         79        CONCAT                                           ~40     ~39, '%3Cbr%3E'
         80        ECHO                                                     ~40
         81      > JMP                                                      ->91
   40    82    >   IS_SMALLER_OR_EQUAL                              ~41     !6, !3
         83      > JMPZ_EX                                          ~41     ~41, ->86
         84    >   IS_SMALLER_OR_EQUAL                              ~42     !4, !6
         85        BOOL                                             ~41     ~42
         86    > > JMPZ                                                     ~41, ->91
   43    87    >   ECHO                                                     '%3Cbr%3E%3Cbr%3EThis+year%3Cbr%3E'
   44    88        FETCH_DIM_R                                      ~43     !5, 'post_id'
         89        CONCAT                                           ~44     ~43, '%3Cbr%3E'
         90        ECHO                                                     ~44
   18    91    > > JMP                                                      ->49
         92    >   FE_FREE                                                  $26
   46    93      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
157.79 ms | 1404 KiB | 19 Q