3v4l.org

run code in 500+ PHP versions simultaneously
<?php $prices = array( array('id' => '28','price' =>100 ), array('id' => '29','price' =>105 ), array('id' => '30','price' =>110 ), array('id' => '31','price' =>115 ), array('id' => '32','price' =>120 ), array('id' => '33','price' =>125 ), array('id' => '34','price' =>130 ) ); $amount = 113; $result_id = null; $take_next = false; foreach ($prices as $item) { if ($item['price'] < $amount) { $take_next = true; } elseif ($item['price'] == $amount){ $result_id = $item['id']; break; } else { if ($take_next){ $result_id = $item['id']; } break; } } echo "Closest ID: $result_id";
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 5, Position 2 = 23
Branch analysis from position: 5
2 jumps found. (Code = 78) Position 1 = 6, Position 2 = 23
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 11
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 22
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 11
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 18
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 23
Branch analysis from position: 23
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 18
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 21
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 23
Branch analysis from position: 23
Branch analysis from position: 21
Branch analysis from position: 23
Branch analysis from position: 23
filename:       /in/d7pMG
function name:  (null)
number of ops:  28
compiled vars:  !0 = $prices, !1 = $amount, !2 = $result_id, !3 = $take_next, !4 = $item
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                       !0, <array>
   12     1        ASSIGN                                                       !1, 113
   13     2        ASSIGN                                                       !2, null
   14     3        ASSIGN                                                       !3, <false>
   15     4      > FE_RESET_R                                           $9      !0, ->23
          5    > > FE_FETCH_R                                                   $9, !4, ->23
   16     6    >   FETCH_DIM_R                                          ~10     !4, 'price'
          7        IS_SMALLER                                                   ~10, !1
          8      > JMPZ                                                         ~11, ->11
   17     9    >   ASSIGN                                                       !3, <true>
   16    10      > JMP                                                          ->22
   18    11    >   FETCH_DIM_R                                          ~13     !4, 'price'
         12        IS_EQUAL                                                     !1, ~13
         13      > JMPZ                                                         ~14, ->18
   19    14    >   FETCH_DIM_R                                          ~15     !4, 'id'
         15        ASSIGN                                                       !2, ~15
   20    16      > JMP                                                          ->23
   18    17*       JMP                                                          ->22
   22    18    > > JMPZ                                                         !3, ->21
   23    19    >   FETCH_DIM_R                                          ~17     !4, 'id'
         20        ASSIGN                                                       !2, ~17
   25    21    > > JMP                                                          ->23
   15    22    > > JMP                                                          ->5
         23    >   FE_FREE                                                      $9
   29    24        NOP                                                          
         25        FAST_CONCAT                                          ~19     'Closest+ID%3A+', !2
         26        ECHO                                                         ~19
         27      > RETURN                                                       1

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
159.61 ms | 1758 KiB | 13 Q