3v4l.org

run code in 300+ PHP versions simultaneously
<?php function niceAuthorsPrint(array $authors, $takeCount){ $totalAuthors = count( $authors ); $tailCount = $totalAuthors - $takeCount; $first = array_slice($authors, 0, $takeCount); $othersLabel = $tailCount == 1 ? 'other' : 'others'; $string = implode( ", ", $first ); if($tailCount > 0){ $string .= " and " . $tailCount . ' ' . $othersLabel; } return $string; } // take 3 echo niceAuthorsPrint(array( 'user1', 'user2', 'user3', 'user4', 'user5' ), 3) ."\n<br>"; // take 4 echo niceAuthorsPrint(array( 'user1', 'user2', 'user3', 'user4', 'user5' ), 4) ."\n<br>"; // take 5 echo niceAuthorsPrint(array( 'user1', 'user2', 'user3', 'user4', 'user5' ), 5) ."\n<br>"; ?>
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/e76Id
function name:  (null)
number of ops:  19
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   22     0  E >   INIT_FCALL                                               'niceauthorsprint'
          1        SEND_VAL                                                 <array>
          2        SEND_VAL                                                 3
          3        DO_FCALL                                      0  $0      
          4        CONCAT                                           ~1      $0, '%0A%3Cbr%3E'
          5        ECHO                                                     ~1
   25     6        INIT_FCALL                                               'niceauthorsprint'
          7        SEND_VAL                                                 <array>
          8        SEND_VAL                                                 4
          9        DO_FCALL                                      0  $2      
         10        CONCAT                                           ~3      $2, '%0A%3Cbr%3E'
         11        ECHO                                                     ~3
   28    12        INIT_FCALL                                               'niceauthorsprint'
         13        SEND_VAL                                                 <array>
         14        SEND_VAL                                                 5
         15        DO_FCALL                                      0  $4      
         16        CONCAT                                           ~5      $4, '%0A%3Cbr%3E'
         17        ECHO                                                     ~5
   30    18      > RETURN                                                   1

Function niceauthorsprint:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 16
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 17
Branch analysis from position: 17
2 jumps found. (Code = 43) Position 1 = 25, Position 2 = 29
Branch analysis from position: 25
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 29
Branch analysis from position: 16
2 jumps found. (Code = 43) Position 1 = 25, Position 2 = 29
Branch analysis from position: 25
Branch analysis from position: 29
filename:       /in/e76Id
function name:  niceAuthorsPrint
number of ops:  31
compiled vars:  !0 = $authors, !1 = $takeCount, !2 = $totalAuthors, !3 = $tailCount, !4 = $first, !5 = $othersLabel, !6 = $string
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    5     2        COUNT                                            ~7      !0
          3        ASSIGN                                                   !2, ~7
    6     4        SUB                                              ~9      !2, !1
          5        ASSIGN                                                   !3, ~9
    8     6        INIT_FCALL                                               'array_slice'
          7        SEND_VAR                                                 !0
          8        SEND_VAL                                                 0
          9        SEND_VAR                                                 !1
         10        DO_ICALL                                         $11     
         11        ASSIGN                                                   !4, $11
   10    12        IS_EQUAL                                                 !3, 1
         13      > JMPZ                                                     ~13, ->16
         14    >   QM_ASSIGN                                        ~14     'other'
         15      > JMP                                                      ->17
         16    >   QM_ASSIGN                                        ~14     'others'
         17    >   ASSIGN                                                   !5, ~14
   12    18        INIT_FCALL                                               'implode'
         19        SEND_VAL                                                 '%2C+'
         20        SEND_VAR                                                 !4
         21        DO_ICALL                                         $16     
         22        ASSIGN                                                   !6, $16
   14    23        IS_SMALLER                                               0, !3
         24      > JMPZ                                                     ~18, ->29
   15    25    >   CONCAT                                           ~19     '+and+', !3
         26        CONCAT                                           ~20     ~19, '+'
         27        CONCAT                                           ~21     ~20, !5
         28        ASSIGN_OP                                     8          !6, ~21
   18    29    > > RETURN                                                   !6
   19    30*     > RETURN                                                   null

End of function niceauthorsprint

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
147.77 ms | 1010 KiB | 18 Q