3v4l.org

run code in 300+ PHP versions simultaneously
<?php $myArray = array("100_1", "100_2", "100_3", "100_11", "101_1", "102_1", "102_2", "103_1", "103_2", "103_3", "104_1", "104_2"); $resultArray = array(); foreach($myArray as $entry) { $parts = explode("_", $entry); $found = FALSE; foreach($resultArray as $key => $resultEntry) { $resultParts = explode("_", $resultEntry); if($parts[0] == $resultParts[0]) { $found = TRUE; if((int)$parts[1] > (int)$resultParts[1]) { $resultArray[$key] = $entry; } } } if(!$found) { $resultArray[] = $entry; } } print_r($resultArray);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 38
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 38
Branch analysis from position: 4
2 jumps found. (Code = 77) Position 1 = 11, Position 2 = 32
Branch analysis from position: 11
2 jumps found. (Code = 78) Position 1 = 12, Position 2 = 32
Branch analysis from position: 12
2 jumps found. (Code = 43) Position 1 = 22, Position 2 = 31
Branch analysis from position: 22
2 jumps found. (Code = 43) Position 1 = 29, Position 2 = 31
Branch analysis from position: 29
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
Branch analysis from position: 31
Branch analysis from position: 31
Branch analysis from position: 32
2 jumps found. (Code = 43) Position 1 = 35, Position 2 = 37
Branch analysis from position: 35
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 37
Branch analysis from position: 32
Branch analysis from position: 38
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 38
filename:       /in/GsGrK
function name:  (null)
number of ops:  43
compiled vars:  !0 = $myArray, !1 = $resultArray, !2 = $entry, !3 = $parts, !4 = $found, !5 = $resultEntry, !6 = $key, !7 = $resultParts
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
    4     1        ASSIGN                                                   !1, <array>
    6     2      > FE_RESET_R                                       $10     !0, ->38
          3    > > FE_FETCH_R                                               $10, !2, ->38
    8     4    >   INIT_FCALL                                               'explode'
          5        SEND_VAL                                                 '_'
          6        SEND_VAR                                                 !2
          7        DO_ICALL                                         $11     
          8        ASSIGN                                                   !3, $11
    9     9        ASSIGN                                                   !4, <false>
   11    10      > FE_RESET_R                                       $14     !1, ->32
         11    > > FE_FETCH_R                                       ~15     $14, !5, ->32
         12    >   ASSIGN                                                   !6, ~15
   13    13        INIT_FCALL                                               'explode'
         14        SEND_VAL                                                 '_'
         15        SEND_VAR                                                 !5
         16        DO_ICALL                                         $17     
         17        ASSIGN                                                   !7, $17
   15    18        FETCH_DIM_R                                      ~19     !3, 0
         19        FETCH_DIM_R                                      ~20     !7, 0
         20        IS_EQUAL                                                 ~19, ~20
         21      > JMPZ                                                     ~21, ->31
   17    22    >   ASSIGN                                                   !4, <true>
   19    23        FETCH_DIM_R                                      ~23     !3, 1
         24        CAST                                          4  ~24     ~23
         25        FETCH_DIM_R                                      ~25     !7, 1
         26        CAST                                          4  ~26     ~25
         27        IS_SMALLER                                               ~26, ~24
         28      > JMPZ                                                     ~27, ->31
   21    29    >   ASSIGN_DIM                                               !1, !6
         30        OP_DATA                                                  !2
   11    31    > > JMP                                                      ->11
         32    >   FE_FREE                                                  $14
   26    33        BOOL_NOT                                         ~29     !4
         34      > JMPZ                                                     ~29, ->37
   28    35    >   ASSIGN_DIM                                               !1
         36        OP_DATA                                                  !2
    6    37    > > JMP                                                      ->3
         38    >   FE_FREE                                                  $10
   33    39        INIT_FCALL                                               'print_r'
         40        SEND_VAR                                                 !1
         41        DO_ICALL                                                 
         42      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
173.57 ms | 1404 KiB | 17 Q