3v4l.org

run code in 300+ PHP versions simultaneously
<?php $json = '[ { "title": "This is the first title", "body": "Lorem ipsum dolor sit amet, consectetur adipiscing elit.", "date": "2015-07-30" }, { "title": "Another article", "body": "Quisqu porttitor dignissim massa rhoncus imperdiet.", "date": "2015-08-18" }, { "title": "The Final Title", "body": "In aliquam auctor ex quis consequat. Praesent non lobortis metus.", "date": "2015-08-30" } ]'; $date = "2015-09-04"; function returnTwoWeeksPrior($jsonString, $dateString) { $decode = json_decode($jsonString); forEach($decode as $decoded) { if (strtotime($decoded->date) > strtotime("$dateString -2 weeks")){ $result = json_encode($decoded); echo $result; } } } echo returnTwoWeeksPrior($json, $date);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OJi80
function name:  (null)
number of ops:  8
compiled vars:  !0 = $json, !1 = $date
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, '%5B%0A++++++++++++%7B%0A++++++++++++++++%22title%22%3A+%22This+is+the+first+title%22%2C%0A++++++++++++++++%22body%22%3A+%22Lorem+ipsum+dolor+sit+amet%2C+consectetur+adipiscing+elit.%22%2C%0A++++++++++++++++%22date%22%3A+%222015-07-30%22%0A++++++++++++%7D%2C%0A++++++++++++%7B%0A++++++++++++++++%22title%22%3A+%22Another+article%22%2C%0A++++++++++++++++%22body%22%3A+%22Quisqu+porttitor+dignissim+massa+rhoncus+imperdiet.%22%2C%0A++++++++++++++++%22date%22%3A+%222015-08-18%22%0A++++++++++++%7D%2C%0A++++++++++++%7B%0A++++++++++++++++%22title%22%3A+%22The+Final+Title%22%2C%0A++++++++++++++++%22body%22%3A+%22In+aliquam+auctor+ex+quis+consequat.+Praesent+non+lobortis+metus.%22%2C%0A++++++++++++++++%22date%22%3A+%222015-08-30%22%0A++++++++++++%7D%0A++++++++%5D'
   21     1        ASSIGN                                                   !1, '2015-09-04'
   34     2        INIT_FCALL                                               'returntwoweeksprior'
          3        SEND_VAR                                                 !0
          4        SEND_VAR                                                 !1
          5        DO_FCALL                                      0  $4      
          6        ECHO                                                     $4
          7      > RETURN                                                   1

Function returntwoweeksprior:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 7, Position 2 = 25
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 25
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 24
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 24
Branch analysis from position: 25
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 25
filename:       /in/OJi80
function name:  returnTwoWeeksPrior
number of ops:  27
compiled vars:  !0 = $jsonString, !1 = $dateString, !2 = $decode, !3 = $decoded, !4 = $result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   25     2        INIT_FCALL                                               'json_decode'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $5      
          5        ASSIGN                                                   !2, $5
   26     6      > FE_RESET_R                                       $7      !2, ->25
          7    > > FE_FETCH_R                                               $7, !3, ->25
   27     8    >   INIT_FCALL                                               'strtotime'
          9        FETCH_OBJ_R                                      ~8      !3, 'date'
         10        SEND_VAL                                                 ~8
         11        DO_ICALL                                         $9      
         12        INIT_FCALL                                               'strtotime'
         13        NOP                                                      
         14        FAST_CONCAT                                      ~10     !1, '+-2+weeks'
         15        SEND_VAL                                                 ~10
         16        DO_ICALL                                         $11     
         17        IS_SMALLER                                               $11, $9
         18      > JMPZ                                                     ~12, ->24
   28    19    >   INIT_FCALL                                               'json_encode'
         20        SEND_VAR                                                 !3
         21        DO_ICALL                                         $13     
         22        ASSIGN                                                   !4, $13
   29    23        ECHO                                                     !4
   26    24    > > JMP                                                      ->7
         25    >   FE_FREE                                                  $7
   32    26      > RETURN                                                   null

End of function returntwoweeksprior

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
127.54 ms | 1407 KiB | 20 Q