3v4l.org

run code in 300+ PHP versions simultaneously
<?php function find_stop_in_routes($routes, $needle, $field = 'stop_code') { $result = []; for ($i = 0, $l = count($routes); $i < $l; $i++) { for ($j = 0, $k = count($routes[$i]['stops']); $j < $k; $j++) { if ($routes[$i]['stops'][$j][$field] == $needle) { $result[$i] = $j; break; } } } return $result; } $routes = [ /* your data def is too big for 3v4l */ ]; $stopCode = 'Your needle'; foreach (find_stop_in_routes($routes, $stopCode) as $routeId => $stopId) { // $routeId is your $i // $stopId is your $j }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 7, Position 2 = 10
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 10
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
filename:       /in/guLoM
function name:  (null)
number of ops:  12
compiled vars:  !0 = $routes, !1 = $stopCode, !2 = $stopId, !3 = $routeId
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   ASSIGN                                                   !0, <array>
   20     1        ASSIGN                                                   !1, 'Your+needle'
   22     2        INIT_FCALL                                               'find_stop_in_routes'
          3        SEND_VAR                                                 !0
          4        SEND_VAR                                                 !1
          5        DO_FCALL                                      0  $6      
          6      > FE_RESET_R                                       $7      $6, ->10
          7    > > FE_FETCH_R                                       ~8      $7, !2, ->10
          8    >   ASSIGN                                                   !3, ~8
          9      > JMP                                                      ->7
         10    >   FE_FREE                                                  $7
   25    11      > RETURN                                                   1

Function find_stop_in_routes:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 27
Branch analysis from position: 27
2 jumps found. (Code = 44) Position 1 = 29, Position 2 = 8
Branch analysis from position: 29
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 24
Branch analysis from position: 24
2 jumps found. (Code = 44) Position 1 = 26, Position 2 = 14
Branch analysis from position: 26
2 jumps found. (Code = 44) Position 1 = 29, Position 2 = 8
Branch analysis from position: 29
Branch analysis from position: 8
Branch analysis from position: 14
2 jumps found. (Code = 43) Position 1 = 20, Position 2 = 23
Branch analysis from position: 20
1 jumps found. (Code = 42) Position 1 = 26
Branch analysis from position: 26
Branch analysis from position: 23
2 jumps found. (Code = 44) Position 1 = 26, Position 2 = 14
Branch analysis from position: 26
Branch analysis from position: 14
filename:       /in/guLoM
function name:  find_stop_in_routes
number of ops:  31
compiled vars:  !0 = $routes, !1 = $needle, !2 = $field, !3 = $result, !4 = $i, !5 = $l, !6 = $j, !7 = $k
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV_INIT                                        !2      'stop_code'
    5     3        ASSIGN                                                   !3, <array>
    7     4        ASSIGN                                                   !4, 0
          5        COUNT                                            ~10     !0
          6        ASSIGN                                                   !5, ~10
          7      > JMP                                                      ->27
    8     8    >   ASSIGN                                                   !6, 0
          9        FETCH_DIM_R                                      ~13     !0, !4
         10        FETCH_DIM_R                                      ~14     ~13, 'stops'
         11        COUNT                                            ~15     ~14
         12        ASSIGN                                                   !7, ~15
         13      > JMP                                                      ->24
    9    14    >   FETCH_DIM_R                                      ~17     !0, !4
         15        FETCH_DIM_R                                      ~18     ~17, 'stops'
         16        FETCH_DIM_R                                      ~19     ~18, !6
         17        FETCH_DIM_R                                      ~20     ~19, !2
         18        IS_EQUAL                                                 !1, ~20
         19      > JMPZ                                                     ~21, ->23
   10    20    >   ASSIGN_DIM                                               !3, !4
         21        OP_DATA                                                  !6
   11    22      > JMP                                                      ->26
    8    23    >   PRE_INC                                                  !6
         24    >   IS_SMALLER                                               !6, !7
         25      > JMPNZ                                                    ~24, ->14
    7    26    >   PRE_INC                                                  !4
         27    >   IS_SMALLER                                               !4, !5
         28      > JMPNZ                                                    ~26, ->8
   16    29    > > RETURN                                                   !3
   17    30*     > RETURN                                                   null

End of function find_stop_in_routes

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
178.34 ms | 1407 KiB | 14 Q