3v4l.org

run code in 300+ PHP versions simultaneously
<?php $json = '{"name":"Test","id_test":8979,"availability":[{"dateStarts":"2019-12-14","dateEnds":"2019-12-21","dateFormat":"Dec 14 - 21, 2019","length":7,"spaces":5,"program":{"id":2,"title":"Long 2/2","program":"WESTERN ISLANDS"},"rate":{"id":2,"title":"Western Islands Program","prices":[{"custom":true,"defaultPrice":"4845","price":"4545","deck":"all cabins & decks","season":"","cabin":""}]}},{"dateStarts":"2019-12-21","dateEnds":"2019-12-28","dateFormat":"Dec 21 - 28, 2019","length":7,"spaces":"-1","program":{"id":1,"title":"Long 1/2","program":"EASTERN ISLANDS"},"rate":{"id":2,"title":"Eastern Islands Program","prices":[{"custom":false,"defaultPrice":"4845","price":"4845","deck":"all cabins & decks","season":"","cabin":""}]}},{"dateStarts":"2019-12-28","dateEnds":"2020-01-04","dateFormat":"Dec 28 - Jan 04 2020","length":7,"spaces":"-1","program":{"id":2,"title":"Long 2/2","program":"WESTERN ISLANDS"},"rate":{"id":2,"title":"Western Islands Program","prices":[{"custom":false,"defaultPrice":"4845","price":"4845","deck":"all cabins & decks","season":"","cabin":""}]}}]}'; $request_data = json_decode( $json ); usort($request_data->availability, function ($a, $b) { return strcmp($a->program->program, $b->program->program); }); echo '<select class="select_availability" name="availability">' . "\n"; $last_program = ''; foreach($request_data->availability as $ava){ if($ava->rate->id == 2){ if ($ava->program->program != $last_program) { if ($last_program != '') echo "</optgroup>\n"; echo '<optgroup label="' . $ava->program->program . '">' . "\n"; $last_program = $ava->program->program; } echo "<option>$ava->dateFormat</option>\n"; } } if ($last_program != '') echo "</optgroup>\n"; echo "</select>\n";
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 15, Position 2 = 42
Branch analysis from position: 15
2 jumps found. (Code = 78) Position 1 = 16, Position 2 = 42
Branch analysis from position: 16
2 jumps found. (Code = 43) Position 1 = 20, Position 2 = 41
Branch analysis from position: 20
2 jumps found. (Code = 43) Position 1 = 24, Position 2 = 36
Branch analysis from position: 24
2 jumps found. (Code = 43) Position 1 = 26, Position 2 = 27
Branch analysis from position: 26
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
Branch analysis from position: 27
Branch analysis from position: 36
Branch analysis from position: 41
Branch analysis from position: 42
2 jumps found. (Code = 43) Position 1 = 45, Position 2 = 46
Branch analysis from position: 45
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 46
Branch analysis from position: 42
filename:       /in/WaAeL
function name:  (null)
number of ops:  48
compiled vars:  !0 = $json, !1 = $request_data, !2 = $last_program, !3 = $ava
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, '%7B%22name%22%3A%22Test%22%2C%22id_test%22%3A8979%2C%22availability%22%3A%5B%7B%22dateStarts%22%3A%222019-12-14%22%2C%22dateEnds%22%3A%222019-12-21%22%2C%22dateFormat%22%3A%22Dec+14+-+21%2C+2019%22%2C%22length%22%3A7%2C%22spaces%22%3A5%2C%22program%22%3A%7B%22id%22%3A2%2C%22title%22%3A%22Long+2%2F2%22%2C%22program%22%3A%22WESTERN+ISLANDS%22%7D%2C%22rate%22%3A%7B%22id%22%3A2%2C%22title%22%3A%22Western+Islands+Program%22%2C%22prices%22%3A%5B%7B%22custom%22%3Atrue%2C%22defaultPrice%22%3A%224845%22%2C%22price%22%3A%224545%22%2C%22deck%22%3A%22all+cabins+%26+decks%22%2C%22season%22%3A%22%22%2C%22cabin%22%3A%22%22%7D%5D%7D%7D%2C%7B%22dateStarts%22%3A%222019-12-21%22%2C%22dateEnds%22%3A%222019-12-28%22%2C%22dateFormat%22%3A%22Dec+21+-+28%2C+2019%22%2C%22length%22%3A7%2C%22spaces%22%3A%22-1%22%2C%22program%22%3A%7B%22id%22%3A1%2C%22title%22%3A%22Long+1%2F2%22%2C%22program%22%3A%22EASTERN+ISLANDS%22%7D%2C%22rate%22%3A%7B%22id%22%3A2%2C%22title%22%3A%22Eastern+Islands+Program%22%2C%22prices%22%3A%5B%7B%22custom%22%3Afalse%2C%22defaultPrice%22%3A%224845%22%2C%22price%22%3A%224845%22%2C%22deck%22%3A%22all+cabins+%26+decks%22%2C%22season%22%3A%22%22%2C%22cabin%22%3A%22%22%7D%5D%7D%7D%2C%7B%22dateStarts%22%3A%222019-12-28%22%2C%22dateEnds%22%3A%222020-01-04%22%2C%22dateFormat%22%3A%22Dec+28+-+Jan+04+2020%22%2C%22length%22%3A7%2C%22spaces%22%3A%22-1%22%2C%22program%22%3A%7B%22id%22%3A2%2C%22title%22%3A%22Long+2%2F2%22%2C%22program%22%3A%22WESTERN+ISLANDS%22%7D%2C%22rate%22%3A%7B%22id%22%3A2%2C%22title%22%3A%22Western+Islands+Program%22%2C%22prices%22%3A%5B%7B%22custom%22%3Afalse%2C%22defaultPrice%22%3A%224845%22%2C%22price%22%3A%224845%22%2C%22deck%22%3A%22all+cabins+%26+decks%22%2C%22season%22%3A%22%22%2C%22cabin%22%3A%22%22%7D%5D%7D%7D%5D%7D'
    4     1        INIT_FCALL                                               'json_decode'
          2        SEND_VAR                                                 !0
          3        DO_ICALL                                         $5      
          4        ASSIGN                                                   !1, $5
    5     5        INIT_FCALL                                               'usort'
          6        FETCH_OBJ_W                                      $7      !1, 'availability'
          7        SEND_REF                                                 $7
          8        DECLARE_LAMBDA_FUNCTION                          ~8      [0]
          9        SEND_VAL                                                 ~8
         10        DO_ICALL                                                 
    6    11        ECHO                                                     '%3Cselect+class%3D%22select_availability%22+name%3D%22availability%22%3E%0A'
    7    12        ASSIGN                                                   !2, ''
    8    13        FETCH_OBJ_R                                      ~11     !1, 'availability'
         14      > FE_RESET_R                                       $12     ~11, ->42
         15    > > FE_FETCH_R                                               $12, !3, ->42
    9    16    >   FETCH_OBJ_R                                      ~13     !3, 'rate'
         17        FETCH_OBJ_R                                      ~14     ~13, 'id'
         18        IS_EQUAL                                                 ~14, 2
         19      > JMPZ                                                     ~15, ->41
   10    20    >   FETCH_OBJ_R                                      ~16     !3, 'program'
         21        FETCH_OBJ_R                                      ~17     ~16, 'program'
         22        IS_NOT_EQUAL                                             !2, ~17
         23      > JMPZ                                                     ~18, ->36
   11    24    >   IS_NOT_EQUAL                                             !2, ''
         25      > JMPZ                                                     ~19, ->27
         26    >   ECHO                                                     '%3C%2Foptgroup%3E%0A'
   12    27    >   FETCH_OBJ_R                                      ~20     !3, 'program'
         28        FETCH_OBJ_R                                      ~21     ~20, 'program'
         29        CONCAT                                           ~22     '%3Coptgroup+label%3D%22', ~21
         30        CONCAT                                           ~23     ~22, '%22%3E'
         31        CONCAT                                           ~24     ~23, '%0A'
         32        ECHO                                                     ~24
   13    33        FETCH_OBJ_R                                      ~25     !3, 'program'
         34        FETCH_OBJ_R                                      ~26     ~25, 'program'
         35        ASSIGN                                                   !2, ~26
   15    36    >   ROPE_INIT                                     3  ~30     '%3Coption%3E'
         37        FETCH_OBJ_R                                      ~28     !3, 'dateFormat'
         38        ROPE_ADD                                      1  ~30     ~30, ~28
         39        ROPE_END                                      2  ~29     ~30, '%3C%2Foption%3E%0A'
         40        ECHO                                                     ~29
    8    41    > > JMP                                                      ->15
         42    >   FE_FREE                                                  $12
   18    43        IS_NOT_EQUAL                                             !2, ''
         44      > JMPZ                                                     ~32, ->46
         45    >   ECHO                                                     '%3C%2Foptgroup%3E%0A'
   19    46    >   ECHO                                                     '%3C%2Fselect%3E%0A'
         47      > RETURN                                                   1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/WaAeL
function name:  {closure}
number of ops:  12
compiled vars:  !0 = $a, !1 = $b
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        INIT_FCALL                                               'strcmp'
          3        FETCH_OBJ_R                                      ~2      !0, 'program'
          4        FETCH_OBJ_R                                      ~3      ~2, 'program'
          5        SEND_VAL                                                 ~3
          6        FETCH_OBJ_R                                      ~4      !1, 'program'
          7        FETCH_OBJ_R                                      ~5      ~4, 'program'
          8        SEND_VAL                                                 ~5
          9        DO_ICALL                                         $6      
         10      > RETURN                                                   $6
         11*     > RETURN                                                   null

End of Dynamic Function 0

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
143.47 ms | 996 KiB | 16 Q