Author: Not specified Language: php
Description: Not specified Timestamp: 2017-10-09 08:30:15 +0000
View raw paste Reply
  1. function numOfLetters($ciphertext){
  2.     $chars = [];
  3.  
  4.     foreach(range('A', 'Z') as $char)
  5.         $chars[] = [
  6.             'count' => substr_count($ciphertext, $char),
  7.             'key' => $char
  8.         ];
  9.  
  10.     usort($chars, function ($a, $b) { // Sort by count descending
  11.         return $a['count'] < $b['count'];
  12.     });
  13.  
  14.     // List letters and count
  15.     print_r($chars);
  16. }
View raw paste Reply