title: PHP Radix Sort Algorithm - Type conversion ok?
body: <p>This is a function I wrote for a Radix Sort in PHP.
  It works for all cases where the array is populated with numbers greater than 0.</p>
  
  <pre><code>function radix_sort($arr) {
  
      // Find the number of passes needed to complete the sort
      $passes = strlen((string)max($arr));
      $buckets = [];
  
      // Start the passes
      for($i = 1; $i &lt;= $passes; $i++) {
          // Create - reinitialize some buckets
          for ($b = 0; $b &lt;= 9; $b++) {
              $buckets[$b] = [];
          }
  
          for ($j = 0; $j &lt; count($arr); $j++) {
              // Drop into the proper bucket based on the significant digit
              $numStr = (string)$arr[$j];
              if (strlen($numStr) &lt; $i) {
                  $bucketsIndex = 0;
              } else {
                  $bucketsIndex = $numStr[strlen($numStr) - $i];
              }
              array_push($buckets[$bucketsIndex], $arr[$j]);
          }
  
          // Repopulate our array by pulling out of our buckets
          $k = 0;
          foreach ($buckets as $bucket) {
              foreach ($bucket as $value) {
                  $arr[$k] = $value;
                  $k++;
              }
          }
      }
      return $arr;
  }
  </code></pre>
  
  <p>I feel like there's too much type converting going on. Is it ok to be doing this? If I wanted to pull the Nth digit from a large number, is there a better way in PHP?</p>