3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = ["\r\n \r\n 300518<\/departureDate>\r\n\t\t\t\t\t\t\t\t\t \r\n\t\t\t\t\t\t\t\t\t \r\n <\/availabilityDetails>\r\n \r\n HYD<\/cityAirport>\r\n <\/departureLocationInfo>\r\n \r\n DXB<\/cityAirport>\r\n <\/arrivalLocationInfo>\r\n <\/availabilityProductInfo>702<\/orderClassesByCabin><\/cabinOption>",44,"AUHOT3116"]; //should yield $desired_output = "300518-departuredate-availabilityDetails-HYD-cityAirport-departureLocationInfo-DXB-cityAirport-arrivalLocationInfo-availabilityProductInfo-702-orderClassesByCabin-44-AUHOT3116"; $trim = ["\t","\r","\n","<\/",">"," ","cabinOption"]; foreach($array as &$value) { $value = str_replace($trim,"-",$value); $value = preg_replace('/[- ]{2,}/','-',$value); $value = trim($value,"- "); } $replaced_output = implode("-",$array); var_dump($desired_output,$replaced_output);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 125) Position 1 = 4, Position 2 = 23
Branch analysis from position: 4
2 jumps found. (Code = 126) Position 1 = 5, Position 2 = 23
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 23
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 23
filename:       /in/uujfC
function name:  (null)
number of ops:  34
compiled vars:  !0 = $array, !1 = $desired_output, !2 = $trim, !3 = $value, !4 = $replaced_output
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, <array>
    5     1        ASSIGN                                                   !1, '300518-departuredate-availabilityDetails-HYD-cityAirport-departureLocationInfo-DXB-cityAirport-arrivalLocationInfo-availabilityProductInfo-702-orderClassesByCabin-44-AUHOT3116'
    7     2        ASSIGN                                                   !2, <array>
    9     3      > FE_RESET_RW                                      $8      !0, ->23
          4    > > FE_FETCH_RW                                              $8, !3, ->23
   10     5    >   INIT_FCALL                                               'str_replace'
          6        SEND_VAR                                                 !2
          7        SEND_VAL                                                 '-'
          8        SEND_VAR                                                 !3
          9        DO_ICALL                                         $9      
         10        ASSIGN                                                   !3, $9
   11    11        INIT_FCALL                                               'preg_replace'
         12        SEND_VAL                                                 '%2F%5B-+%5D%7B2%2C%7D%2F'
         13        SEND_VAL                                                 '-'
         14        SEND_VAR                                                 !3
         15        DO_ICALL                                         $11     
         16        ASSIGN                                                   !3, $11
   12    17        INIT_FCALL                                               'trim'
         18        SEND_VAR                                                 !3
         19        SEND_VAL                                                 '-+'
         20        DO_ICALL                                         $13     
         21        ASSIGN                                                   !3, $13
    9    22      > JMP                                                      ->4
         23    >   FE_FREE                                                  $8
   15    24        INIT_FCALL                                               'implode'
         25        SEND_VAL                                                 '-'
         26        SEND_VAR                                                 !0
         27        DO_ICALL                                         $15     
         28        ASSIGN                                                   !4, $15
   17    29        INIT_FCALL                                               'var_dump'
         30        SEND_VAR                                                 !1
         31        SEND_VAR                                                 !4
         32        DO_ICALL                                                 
         33      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
147.44 ms | 1396 KiB | 23 Q