3v4l.org

run code in 300+ PHP versions simultaneously
<?php $text = "Ham followed now ecstatic use speaking exercise may repeated. Himself he evident oh greatly my on inhabit general concern. It allowance prevailed enjoyment in it. Calling observe for who pressed raising his. Can connection instrument astonished unaffected his motionless preference. Announcing say boy precaution unaffected difficulty alteration him."; $word = "Potato"; $needleCharCounts = count_chars(strtolower($word), 1); $haystackCharCounts = count_chars(strtolower($text), 1); $result = null; foreach ($needleCharCounts as $letter => $count) { $result = min($result ?? PHP_INT_MAX, intdiv($haystackCharCounts[$letter] ?? 0, $count)); echo "$result :: " . chr($letter) . ": $count versus " . $haystackCharCounts[$letter] . "\n"; if ($result === 0) { break; } } echo $result ?? 0; // "a" can be found 22 times. // "o" can be found 20 times, so two "o"s can be found 10 times. // "p" can be found 6 times. // "t" can be found 20 times, so two "t"s can be found 10 times.
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 20, Position 2 = 54
Branch analysis from position: 20
2 jumps found. (Code = 78) Position 1 = 21, Position 2 = 54
Branch analysis from position: 21
2 jumps found. (Code = 43) Position 1 = 52, Position 2 = 53
Branch analysis from position: 52
1 jumps found. (Code = 42) Position 1 = 54
Branch analysis from position: 54
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 53
1 jumps found. (Code = 42) Position 1 = 20
Branch analysis from position: 20
Branch analysis from position: 54
Branch analysis from position: 54
filename:       /in/rXBFH
function name:  (null)
number of ops:  59
compiled vars:  !0 = $text, !1 = $word, !2 = $needleCharCounts, !3 = $haystackCharCounts, !4 = $result, !5 = $count, !6 = $letter
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, 'Ham+followed+now+ecstatic+use+speaking+exercise+may+repeated.%0AHimself+he+evident+oh+greatly+my+on+inhabit+general+concern.+It+allowance+%0Aprevailed+enjoyment+in+it.+Calling+observe+for+who+pressed+raising+his.+Can+%0Aconnection+instrument+astonished+unaffected+his+motionless+preference.+%0AAnnouncing+say+boy+precaution+unaffected+difficulty+alteration+him.'
    9     1        ASSIGN                                                   !1, 'Potato'
   11     2        INIT_FCALL                                               'count_chars'
          3        INIT_FCALL                                               'strtolower'
          4        SEND_VAR                                                 !1
          5        DO_ICALL                                         $9      
          6        SEND_VAR                                                 $9
          7        SEND_VAL                                                 1
          8        DO_ICALL                                         $10     
          9        ASSIGN                                                   !2, $10
   12    10        INIT_FCALL                                               'count_chars'
         11        INIT_FCALL                                               'strtolower'
         12        SEND_VAR                                                 !0
         13        DO_ICALL                                         $12     
         14        SEND_VAR                                                 $12
         15        SEND_VAL                                                 1
         16        DO_ICALL                                         $13     
         17        ASSIGN                                                   !3, $13
   14    18        ASSIGN                                                   !4, null
   15    19      > FE_RESET_R                                       $16     !2, ->54
         20    > > FE_FETCH_R                                       ~17     $16, !5, ->54
         21    >   ASSIGN                                                   !6, ~17
   16    22        INIT_FCALL                                               'min'
         23        COALESCE                                         ~19     !4
         24        QM_ASSIGN                                        ~19     9223372036854775807
         25        SEND_VAL                                                 ~19
         26        INIT_FCALL                                               'intdiv'
         27        FETCH_DIM_IS                                     ~20     !3, !6
         28        COALESCE                                         ~21     ~20
         29        QM_ASSIGN                                        ~21     0
         30        SEND_VAL                                                 ~21
         31        SEND_VAR                                                 !5
         32        DO_ICALL                                         $22     
         33        SEND_VAR                                                 $22
         34        DO_ICALL                                         $23     
         35        ASSIGN                                                   !4, $23
   17    36        NOP                                                      
         37        FAST_CONCAT                                      ~25     !4, '+%3A%3A+'
         38        INIT_FCALL                                               'chr'
         39        SEND_VAR                                                 !6
         40        DO_ICALL                                         $26     
         41        CONCAT                                           ~27     ~25, $26
         42        ROPE_INIT                                     3  ~29     '%3A+'
         43        ROPE_ADD                                      1  ~29     ~29, !5
         44        ROPE_END                                      2  ~28     ~29, '+versus+'
         45        CONCAT                                           ~31     ~27, ~28
         46        FETCH_DIM_R                                      ~32     !3, !6
         47        CONCAT                                           ~33     ~31, ~32
         48        CONCAT                                           ~34     ~33, '%0A'
         49        ECHO                                                     ~34
   18    50        IS_IDENTICAL                                             !4, 0
         51      > JMPZ                                                     ~35, ->53
   19    52    > > JMP                                                      ->54
   15    53    > > JMP                                                      ->20
         54    >   FE_FREE                                                  $16
   22    55        COALESCE                                         ~36     !4
         56        QM_ASSIGN                                        ~36     0
         57        ECHO                                                     ~36
   27    58      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
142.93 ms | 1009 KiB | 18 Q