<?php
function generateRandomString($length = 10, $alpha = false, $numeric = false) {
  if ($alpha)   { $characters = 'ABCDEFGHJKLMNPQRSTUVWXYZ'; }
  if ($numeric) { $characters = '0123456789'; }
  $charactersLength = strlen($characters);
  $randomString = '';
  for ($i = 0; $i < $length; ++$i) {
    $randomString .= $characters[rand(0, $charactersLength - 1)];
  }
  if (substr($randomString, 0, 1) != 2) { // if doesn't start with 2
    generateRandomString($length, $alpha, $numeric); // try again
  }
  else {
    return $randomString;
  }
}
$num = generateRandomString(8, false, true);
echo ($num);
I need it to return a value starting with 2 but it doesn't return anything at all, no errors either. What am I doing wrong here?
 
    