3v4l.org

run code in 300+ PHP versions simultaneously
<?php function getColor($rgb) { $colors = array($BLUE =>0x0a9ef3, $RED => 0xea0a2f, $GREEN => 0x336633); $largestDiff = 0; $closestColor = ""; foreach ($colors as $name => $rgbColor) { if (!isset($smallestDiff)) { $smallestDiff = colorDiff($rgbColor,$rgb); $closestColor = $name; } else if (colorDiff($rgbColor,$rgb) < $smallestDiff) { $smallestDiff = colorDiff($rgbColor,$rgb); $closestColor = $name; } } return $closestColor; } function colorDiff($rgb1,$rgb2) { // do the math on each tuple $red1 = hexdec(substr($rgb1,0,2)); $green1 = hexdec(substr($rgb1,2,2)); $blue1 = hexdec(substr($rgb1,4,2)); $red2 = hexdec(substr($rgb2,0,2)); $green2 = hexdec(substr($rgb2,2,2)); $blue2 = hexdec(substr($rgb2,4,2)); return abs($red1 - $red2) + abs($green1 - $green2) + abs($blue1 - $blue2) ; } $color = '336633'; $closestmatch = getColor("0x".$color); echo $closematch; ?>
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/6NOca
function name:  (null)
number of ops:  8
compiled vars:  !0 = $color, !1 = $closestmatch, !2 = $closematch
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   45     0  E >   ASSIGN                                                   !0, '336633'
   46     1        INIT_FCALL                                               'getcolor'
          2        CONCAT                                           ~4      '0x', !0
          3        SEND_VAL                                                 ~4
          4        DO_FCALL                                      0  $5      
          5        ASSIGN                                                   !1, $5
   47     6        ECHO                                                     !2
   52     7      > RETURN                                                   1

Function getcolor:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 8, Position 2 = 33
Branch analysis from position: 8
2 jumps found. (Code = 78) Position 1 = 9, Position 2 = 33
Branch analysis from position: 9
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 20
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 32
Branch analysis from position: 32
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 20
2 jumps found. (Code = 43) Position 1 = 26, Position 2 = 32
Branch analysis from position: 26
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 32
Branch analysis from position: 33
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 33
filename:       /in/6NOca
function name:  getColor
number of ops:  36
compiled vars:  !0 = $rgb, !1 = $colors, !2 = $BLUE, !3 = $RED, !4 = $GREEN, !5 = $largestDiff, !6 = $closestColor, !7 = $rgbColor, !8 = $name, !9 = $smallestDiff
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    6     1        INIT_ARRAY                                       ~10     696051, !2
          2        ADD_ARRAY_ELEMENT                                ~10     15338031, !3
          3        ADD_ARRAY_ELEMENT                                ~10     3368499, !4
          4        ASSIGN                                                   !1, ~10
    8     5        ASSIGN                                                   !5, 0
    9     6        ASSIGN                                                   !6, ''
   10     7      > FE_RESET_R                                       $14     !1, ->33
          8    > > FE_FETCH_R                                       ~15     $14, !7, ->33
          9    >   ASSIGN                                                   !8, ~15
   12    10        ISSET_ISEMPTY_CV                                 ~17     !9
         11        BOOL_NOT                                         ~18     ~17
         12      > JMPZ                                                     ~18, ->20
   14    13    >   INIT_FCALL_BY_NAME                                       'colorDiff'
         14        SEND_VAR_EX                                              !7
         15        SEND_VAR_EX                                              !0
         16        DO_FCALL                                      0  $19     
         17        ASSIGN                                                   !9, $19
   15    18        ASSIGN                                                   !6, !8
         19      > JMP                                                      ->32
   17    20    >   INIT_FCALL_BY_NAME                                       'colorDiff'
         21        SEND_VAR_EX                                              !7
         22        SEND_VAR_EX                                              !0
         23        DO_FCALL                                      0  $22     
         24        IS_SMALLER                                               $22, !9
         25      > JMPZ                                                     ~23, ->32
   19    26    >   INIT_FCALL_BY_NAME                                       'colorDiff'
         27        SEND_VAR_EX                                              !7
         28        SEND_VAR_EX                                              !0
         29        DO_FCALL                                      0  $24     
         30        ASSIGN                                                   !9, $24
   20    31        ASSIGN                                                   !6, !8
   10    32    > > JMP                                                      ->8
         33    >   FE_FREE                                                  $14
   24    34      > RETURN                                                   !6
   26    35*     > RETURN                                                   null

End of function getcolor

Function colordiff:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/6NOca
function name:  colorDiff
number of ops:  72
compiled vars:  !0 = $rgb1, !1 = $rgb2, !2 = $red1, !3 = $green1, !4 = $blue1, !5 = $red2, !6 = $green2, !7 = $blue2
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   28     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   32     2        INIT_FCALL                                               'hexdec'
          3        INIT_FCALL                                               'substr'
          4        SEND_VAR                                                 !0
          5        SEND_VAL                                                 0
          6        SEND_VAL                                                 2
          7        DO_ICALL                                         $8      
          8        SEND_VAR                                                 $8
          9        DO_ICALL                                         $9      
         10        ASSIGN                                                   !2, $9
   33    11        INIT_FCALL                                               'hexdec'
         12        INIT_FCALL                                               'substr'
         13        SEND_VAR                                                 !0
         14        SEND_VAL                                                 2
         15        SEND_VAL                                                 2
         16        DO_ICALL                                         $11     
         17        SEND_VAR                                                 $11
         18        DO_ICALL                                         $12     
         19        ASSIGN                                                   !3, $12
   34    20        INIT_FCALL                                               'hexdec'
         21        INIT_FCALL                                               'substr'
         22        SEND_VAR                                                 !0
         23        SEND_VAL                                                 4
         24        SEND_VAL                                                 2
         25        DO_ICALL                                         $14     
         26        SEND_VAR                                                 $14
         27        DO_ICALL                                         $15     
         28        ASSIGN                                                   !4, $15
   36    29        INIT_FCALL                                               'hexdec'
         30        INIT_FCALL                                               'substr'
         31        SEND_VAR                                                 !1
         32        SEND_VAL                                                 0
         33        SEND_VAL                                                 2
         34        DO_ICALL                                         $17     
         35        SEND_VAR                                                 $17
         36        DO_ICALL                                         $18     
         37        ASSIGN                                                   !5, $18
   37    38        INIT_FCALL                                               'hexdec'
         39        INIT_FCALL                                               'substr'
         40        SEND_VAR                                                 !1
         41        SEND_VAL                                                 2
         42        SEND_VAL                                                 2
         43        DO_ICALL                                         $20     
         44        SEND_VAR                                                 $20
         45        DO_ICALL                                         $21     
         46        ASSIGN                                                   !6, $21
   38    47        INIT_FCALL                                               'hexdec'
         48        INIT_FCALL                                               'substr'
         49        SEND_VAR                                                 !1
         50        SEND_VAL                                                 4
         51        SEND_VAL                                                 2
         52        DO_ICALL                                         $23     
         53        SEND_VAR                                                 $23
         54        DO_ICALL                                         $24     
         55        ASSIGN                                                   !7, $24
   40    56        INIT_FCALL                                               'abs'
         57        SUB                                              ~26     !2, !5
         58        SEND_VAL                                                 ~26
         59        DO_ICALL                                         $27     
         60        INIT_FCALL                                               'abs'
         61        SUB                                              ~28     !3, !6
         62        SEND_VAL                                                 ~28
         63        DO_ICALL                                         $29     
         64        ADD                                              ~30     $27, $29
         65        INIT_FCALL                                               'abs'
         66        SUB                                              ~31     !4, !7
         67        SEND_VAL                                                 ~31
         68        DO_ICALL                                         $32     
         69        ADD                                              ~33     ~30, $32
         70      > RETURN                                                   ~33
   43    71*     > RETURN                                                   null

End of function colordiff

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
152.86 ms | 1407 KiB | 20 Q