3v4l.org

run code in 500+ 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","<\/",">"," "]; 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 = 14
Branch analysis from position: 4
2 jumps found. (Code = 126) Position 1 = 5, Position 2 = 14
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
filename:       /in/3cdqO
function name:  (null)
number of ops:  22
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, ->14
          4    > > FE_FETCH_RW                                                  $8, !3, ->14
   10     5    >   FRAMELESS_ICALL_3                str_replace         ~9      !2, '-'
          6        OP_DATA                                                      !3
          7        ASSIGN                                                       !3, ~9
   11     8        FRAMELESS_ICALL_3                preg_replace        ~11     '%2F%5B-+%5D%7B2%2C%7D%2F', '-'
          9        OP_DATA                                                      !3
         10        ASSIGN                                                       !3, ~11
   12    11        FRAMELESS_ICALL_2                trim                ~13     !3, '-+'
         12        ASSIGN                                                       !3, ~13
    9    13      > JMP                                                          ->4
         14    >   FE_FREE                                                      $8
   15    15        FRAMELESS_ICALL_2                implode             ~15     '-', !0
         16        ASSIGN                                                       !4, ~15
   17    17        INIT_FCALL                                                   'var_dump'
         18        SEND_VAR                                                     !1
         19        SEND_VAR                                                     !4
         20        DO_ICALL                                                     
         21      > RETURN                                                       1

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
165.56 ms | 3496 KiB | 14 Q