3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = Array( '0' => Array ( 'payment' => 1, 'amount' => 100) , '1' => Array ( 'payment' => 2, 'amount' => 300 ) , '2' => Array ( 'payment' => 3, 'amount' => 800 ) ); function getNearest($search, $arr) { $closest = null; foreach ($arr as $item) { if ($closest === null || abs($search - $closest) > abs($item - $search)) { $closest = $item; } } return $closest; } $key = array_search(getNearest(350, array_column($array,'amount')),array_column($array,'amount')); echo $array[$key]['payment'];
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/spN2q
function name:  (null)
number of ops:  22
compiled vars:  !0 = $array, !1 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   ASSIGN                                                   !0, <array>
   20     1        INIT_FCALL                                               'array_search'
          2        INIT_FCALL                                               'getnearest'
          3        SEND_VAL                                                 350
          4        INIT_FCALL                                               'array_column'
          5        SEND_VAR                                                 !0
          6        SEND_VAL                                                 'amount'
          7        DO_ICALL                                         $3      
          8        SEND_VAR                                                 $3
          9        DO_FCALL                                      0  $4      
         10        SEND_VAR                                                 $4
         11        INIT_FCALL                                               'array_column'
         12        SEND_VAR                                                 !0
         13        SEND_VAL                                                 'amount'
         14        DO_ICALL                                         $5      
         15        SEND_VAR                                                 $5
         16        DO_ICALL                                         $6      
         17        ASSIGN                                                   !1, $6
   22    18        FETCH_DIM_R                                      ~8      !0, !1
         19        FETCH_DIM_R                                      ~9      ~8, 'payment'
         20        ECHO                                                     ~9
         21      > RETURN                                                   1

Function getnearest:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 20
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 20
Branch analysis from position: 5
2 jumps found. (Code = 47) Position 1 = 7, Position 2 = 17
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 18, Position 2 = 19
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 19
Branch analysis from position: 17
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
filename:       /in/spN2q
function name:  getNearest
number of ops:  23
compiled vars:  !0 = $search, !1 = $arr, !2 = $closest, !3 = $item
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   11     2        ASSIGN                                                   !2, null
   12     3      > FE_RESET_R                                       $5      !1, ->20
          4    > > FE_FETCH_R                                               $5, !3, ->20
   13     5    >   TYPE_CHECK                                    2  ~6      !2
          6      > JMPNZ_EX                                         ~6      ~6, ->17
          7    >   INIT_FCALL                                               'abs'
          8        SUB                                              ~7      !0, !2
          9        SEND_VAL                                                 ~7
         10        DO_ICALL                                         $8      
         11        INIT_FCALL                                               'abs'
         12        SUB                                              ~9      !3, !0
         13        SEND_VAL                                                 ~9
         14        DO_ICALL                                         $10     
         15        IS_SMALLER                                       ~11     $10, $8
         16        BOOL                                             ~6      ~11
         17    > > JMPZ                                                     ~6, ->19
   14    18    >   ASSIGN                                                   !2, !3
   12    19    > > JMP                                                      ->4
         20    >   FE_FREE                                                  $5
   17    21      > RETURN                                                   !2
   18    22*     > RETURN                                                   null

End of function getnearest

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
163.46 ms | 1014 KiB | 17 Q