3v4l.org

run code in 500+ PHP versions simultaneously
<?php function extractCalibrationValues($lines) { $totalCalibration = 0; foreach ($lines as $line) { $calibrationValue = getCalibrationValue($line); $totalCalibration += $calibrationValue; } return $totalCalibration; } function getCalibrationValue($line) { // Use regular expression to find the first and last digits in the line preg_match('/\d/', $line, $matchesFirstDigit); preg_match_all('/\d(?=\D*$)/', $line, $matchesLastDigit); // Combine the first and last digits to form a two-digit number $calibrationValue = (int)($matchesFirstDigit[0] . end($matchesLastDigit[0])); return $calibrationValue; } // Example lines $lines = [ "1abc2", "pqr3stu8vwx", "a1b2c3d4e5f", "treb7uchet", ]; // Calculate and output the total calibration value $totalCalibration = extractCalibrationValues($lines); echo "Total Calibration Value: $totalCalibration\n"; ?>
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/QT9l4
function name:  (null)
number of ops:  10
compiled vars:  !0 = $lines, !1 = $totalCalibration
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   26     0  E >   ASSIGN                                                       !0, <array>
   34     1        INIT_FCALL                                                   'extractcalibrationvalues'
          2        SEND_VAR                                                     !0
          3        DO_FCALL                                          0  $3      
          4        ASSIGN                                                       !1, $3
   35     5        ROPE_INIT                                         3  ~6      'Total+Calibration+Value%3A+'
          6        ROPE_ADD                                          1  ~6      ~6, !1
          7        ROPE_END                                          2  ~5      ~6, '%0A'
          8        ECHO                                                         ~5
   37     9      > RETURN                                                       1

Function extractcalibrationvalues:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 10
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 10
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
filename:       /in/QT9l4
function name:  extractCalibrationValues
number of ops:  13
compiled vars:  !0 = $lines, !1 = $totalCalibration, !2 = $line, !3 = $calibrationValue
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   RECV                                                 !0      
    4     1        ASSIGN                                                       !1, 0
    6     2      > FE_RESET_R                                           $5      !0, ->10
          3    > > FE_FETCH_R                                                   $5, !2, ->10
    7     4    >   INIT_FCALL_BY_NAME                                           'getCalibrationValue'
          5        SEND_VAR_EX                                                  !2
          6        DO_FCALL                                          0  $6      
          7        ASSIGN                                                       !3, $6
    8     8        ASSIGN_OP                                         1          !1, !3
    6     9      > JMP                                                          ->3
         10    >   FE_FREE                                                      $5
   11    11      > RETURN                                                       !1
   12    12*     > RETURN                                                       null

End of function extractcalibrationvalues

Function getcalibrationvalue:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/QT9l4
function name:  getCalibrationValue
number of ops:  21
compiled vars:  !0 = $line, !1 = $matchesFirstDigit, !2 = $matchesLastDigit, !3 = $calibrationValue
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   14     0  E >   RECV                                                 !0      
   16     1        INIT_FCALL                                                   'preg_match'
          2        SEND_VAL                                                     '%2F%5Cd%2F'
          3        SEND_VAR                                                     !0
          4        SEND_REF                                                     !1
          5        DO_ICALL                                                     
   17     6        INIT_FCALL                                                   'preg_match_all'
          7        SEND_VAL                                                     '%2F%5Cd%28%3F%3D%5CD%2A%24%29%2F'
          8        SEND_VAR                                                     !0
          9        SEND_REF                                                     !2
         10        DO_ICALL                                                     
   20    11        FETCH_DIM_R                                          ~6      !1, 0
         12        INIT_FCALL                                                   'end'
         13        FETCH_DIM_W                                          $7      !2, 0
         14        SEND_REF                                                     $7
         15        DO_ICALL                                             $8      
         16        CONCAT                                               ~9      ~6, $8
         17        CAST                                              4  ~10     ~9
         18        ASSIGN                                                       !3, ~10
   22    19      > RETURN                                                       !3
   23    20*     > RETURN                                                       null

End of function getcalibrationvalue

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
126.88 ms | 496 KiB | 13 Q