3v4l.org

run code in 300+ PHP versions simultaneously
<?php $words=['MVW','MWAH','MWAH','MYW','MW','MY9AH','MYQAH','MYQAH','MY9AH','MYQAH', 'MYQAH','MWAH','MYQAH','MYSWI','MYQAH','MYQAH','MW','MW','MW','MW']; echo "*** Step #1: Replace each word with an array of its characters ***\n"; var_export(array_map('str_split',$words)); echo "\n\n---\n\n"; echo "*** Step #2: Pass the characters through array_map with the splat operator and func_get_args() to isolate columnar data including NULLs where no character exists in the column ***\n"; var_export(array_map(function(){return func_get_args();},...array_map('str_split',$words))); echo "\n\n---\n\n"; echo "*** Step #3: Convert column data to strings with the added benefit of eliminating NULLs ***\n"; //var_export(array_map(function(){return implode(func_get_args());},...array_map('str_split',$words))); echo "\n\n---\n\n"; echo "*** Step #4: Count the occurrences of each character; stored as ord values as keys, and occurrences as values ***\n"; var_export(array_map(function(){return count_chars(implode(func_get_args()),1);},...array_map('str_split',$words))); echo "\n\n---\n\n"; echo "*** Step #5: Sort DESC while preserving keys ***\n"; var_export(array_map(function(){$occurrences=count_chars(implode(func_get_args()),1); arsort($occurrences); return $occurrences;},...array_map('str_split',$words))); echo "\n\n---\n\n"; echo "*** Step #6: Target the first (highest occurring) value/character in the array ***\n"; var_export(array_map(function(){$occurrences=count_chars(implode(func_get_args()),1); arsort($occurrences); return key($occurrences);},...array_map('str_split',$words))); echo "\n\n---\n\n"; echo "*** Step #7: Convert the targeted character from ord() to chr() ***\n"; var_export(array_map(function(){$occurrences=count_chars(implode(func_get_args()),1); arsort($occurrences); return chr(key($occurrences));},...array_map('str_split',$words)));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/WAOvW
function name:  (null)
number of ops:  87
compiled vars:  !0 = $words
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, <array>
    5     1        ECHO                                                     '%2A%2A%2A+Step+%231%3A++Replace+each+word+with+an+array+of+its+characters+%2A%2A%2A%0A'
    6     2        INIT_FCALL                                               'var_export'
          3        INIT_FCALL                                               'array_map'
          4        SEND_VAL                                                 'str_split'
          5        SEND_VAR                                                 !0
          6        DO_ICALL                                         $2      
          7        SEND_VAR                                                 $2
          8        DO_ICALL                                                 
    7     9        ECHO                                                     '%0A%0A---%0A%0A'
    9    10        ECHO                                                     '%2A%2A%2A+Step+%232%3A++Pass+the+characters+through+array_map+with+the+splat+operator+and+func_get_args%28%29+to+isolate+columnar+data+including+NULLs+where+no+character+exists+in+the+column+%2A%2A%2A%0A'
   10    11        INIT_FCALL                                               'var_export'
         12        INIT_FCALL                                               'array_map'
         13        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FWAOvW%3A10%240'
         14        SEND_VAL                                                 ~4
         15        INIT_FCALL                                               'array_map'
         16        SEND_VAL                                                 'str_split'
         17        SEND_VAR                                                 !0
         18        DO_ICALL                                         $5      
         19        SEND_UNPACK                                              $5
         20        CHECK_UNDEF_ARGS                                         
         21        DO_ICALL                                         $6      
         22        SEND_VAR                                                 $6
         23        DO_ICALL                                                 
   11    24        ECHO                                                     '%0A%0A---%0A%0A'
   13    25        ECHO                                                     '%2A%2A%2A+Step+%233%3A++Convert+column+data+to+strings+with+the+added+benefit+of+eliminating+NULLs+%2A%2A%2A%0A'
   15    26        ECHO                                                     '%0A%0A---%0A%0A'
   17    27        ECHO                                                     '%2A%2A%2A+Step+%234%3A++Count+the+occurrences+of+each+character%3B+stored+as+ord+values+as+keys%2C+and+occurrences+as+values+%2A%2A%2A%0A'
   18    28        INIT_FCALL                                               'var_export'
         29        INIT_FCALL                                               'array_map'
         30        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FWAOvW%3A18%241'
         31        SEND_VAL                                                 ~8
         32        INIT_FCALL                                               'array_map'
         33        SEND_VAL                                                 'str_split'
         34        SEND_VAR                                                 !0
         35        DO_ICALL                                         $9      
         36        SEND_UNPACK                                              $9
         37        CHECK_UNDEF_ARGS                                         
         38        DO_ICALL                                         $10     
         39        SEND_VAR                                                 $10
         40        DO_ICALL                                                 
   19    41        ECHO                                                     '%0A%0A---%0A%0A'
   21    42        ECHO                                                     '%2A%2A%2A+Step+%235%3A++Sort+DESC+while+preserving+keys+%2A%2A%2A%0A'
   22    43        INIT_FCALL                                               'var_export'
         44        INIT_FCALL                                               'array_map'
         45        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FWAOvW%3A22%242'
         46        SEND_VAL                                                 ~12
         47        INIT_FCALL                                               'array_map'
         48        SEND_VAL                                                 'str_split'
         49        SEND_VAR                                                 !0
         50        DO_ICALL                                         $13     
         51        SEND_UNPACK                                              $13
         52        CHECK_UNDEF_ARGS                                         
         53        DO_ICALL                                         $14     
         54        SEND_VAR                                                 $14
         55        DO_ICALL                                                 
   23    56        ECHO                                                     '%0A%0A---%0A%0A'
   25    57        ECHO                                                     '%2A%2A%2A+Step+%236%3A++Target+the+first+%28highest+occurring%29+value%2Fcharacter+in+the+array+%2A%2A%2A%0A'
   26    58        INIT_FCALL                                               'var_export'
         59        INIT_FCALL                                               'array_map'
         60        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FWAOvW%3A26%243'
         61        SEND_VAL                                                 ~16
         62        INIT_FCALL                                               'array_map'
         63        SEND_VAL                                                 'str_split'
         64        SEND_VAR                                                 !0
         65        DO_ICALL                                         $17     
         66        SEND_UNPACK                                              $17
         67        CHECK_UNDEF_ARGS                                         
         68        DO_ICALL                                         $18     
         69        SEND_VAR                                                 $18
         70        DO_ICALL                                                 
   27    71        ECHO                                                     '%0A%0A---%0A%0A'
   29    72        ECHO                                                     '%2A%2A%2A+Step+%237%3A++Convert+the+targeted+character+from+ord%28%29+to+chr%28%29+%2A%2A%2A%0A'
   30    73        INIT_FCALL                                               'var_export'
         74        INIT_FCALL                                               'array_map'
         75        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FWAOvW%3A30%244'
         76        SEND_VAL                                                 ~20
         77        INIT_FCALL                                               'array_map'
         78        SEND_VAL                                                 'str_split'
         79        SEND_VAR                                                 !0
         80        DO_ICALL                                         $21     
         81        SEND_UNPACK                                              $21
         82        CHECK_UNDEF_ARGS                                         
         83        DO_ICALL                                         $22     
         84        SEND_VAR                                                 $22
         85        DO_ICALL                                                 
         86      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2FWAOvW%3A10%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/WAOvW
function name:  {closure}
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     0  E >   FUNC_GET_ARGS                                    ~0      
          1      > RETURN                                                   ~0
          2*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FWAOvW%3A10%240

Function %00%7Bclosure%7D%2Fin%2FWAOvW%3A18%241:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/WAOvW
function name:  {closure}
number of ops:  10
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   INIT_FCALL                                               'count_chars'
          1        INIT_FCALL                                               'implode'
          2        FUNC_GET_ARGS                                    ~0      
          3        SEND_VAL                                                 ~0
          4        DO_ICALL                                         $1      
          5        SEND_VAR                                                 $1
          6        SEND_VAL                                                 1
          7        DO_ICALL                                         $2      
          8      > RETURN                                                   $2
          9*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FWAOvW%3A18%241

Function %00%7Bclosure%7D%2Fin%2FWAOvW%3A22%242:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/WAOvW
function name:  {closure}
number of ops:  14
compiled vars:  !0 = $occurrences
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   22     0  E >   INIT_FCALL                                               'count_chars'
          1        INIT_FCALL                                               'implode'
          2        FUNC_GET_ARGS                                    ~1      
          3        SEND_VAL                                                 ~1
          4        DO_ICALL                                         $2      
          5        SEND_VAR                                                 $2
          6        SEND_VAL                                                 1
          7        DO_ICALL                                         $3      
          8        ASSIGN                                                   !0, $3
          9        INIT_FCALL                                               'arsort'
         10        SEND_REF                                                 !0
         11        DO_ICALL                                                 
         12      > RETURN                                                   !0
         13*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FWAOvW%3A22%242

Function %00%7Bclosure%7D%2Fin%2FWAOvW%3A26%243:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/WAOvW
function name:  {closure}
number of ops:  17
compiled vars:  !0 = $occurrences
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   INIT_FCALL                                               'count_chars'
          1        INIT_FCALL                                               'implode'
          2        FUNC_GET_ARGS                                    ~1      
          3        SEND_VAL                                                 ~1
          4        DO_ICALL                                         $2      
          5        SEND_VAR                                                 $2
          6        SEND_VAL                                                 1
          7        DO_ICALL                                         $3      
          8        ASSIGN                                                   !0, $3
          9        INIT_FCALL                                               'arsort'
         10        SEND_REF                                                 !0
         11        DO_ICALL                                                 
         12        INIT_FCALL                                               'key'
         13        SEND_VAR                                                 !0
         14        DO_ICALL                                         $6      
         15      > RETURN                                                   $6
         16*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FWAOvW%3A26%243

Function %00%7Bclosure%7D%2Fin%2FWAOvW%3A30%244:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/WAOvW
function name:  {closure}
number of ops:  20
compiled vars:  !0 = $occurrences
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   30     0  E >   INIT_FCALL                                               'count_chars'
          1        INIT_FCALL                                               'implode'
          2        FUNC_GET_ARGS                                    ~1      
          3        SEND_VAL                                                 ~1
          4        DO_ICALL                                         $2      
          5        SEND_VAR                                                 $2
          6        SEND_VAL                                                 1
          7        DO_ICALL                                         $3      
          8        ASSIGN                                                   !0, $3
          9        INIT_FCALL                                               'arsort'
         10        SEND_REF                                                 !0
         11        DO_ICALL                                                 
         12        INIT_FCALL                                               'chr'
         13        INIT_FCALL                                               'key'
         14        SEND_VAR                                                 !0
         15        DO_ICALL                                         $6      
         16        SEND_VAR                                                 $6
         17        DO_ICALL                                         $7      
         18      > RETURN                                                   $7
         19*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FWAOvW%3A30%244

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
131.49 ms | 1413 KiB | 27 Q