function to append "a" or "an" to the front of a number as appropriate Input: any integer

Output: that integer in number format (commas) with a leading a or an as appropriate with the rules of English

After a bit of groping around I hacked out the following PHP function, and am looking for any advice on code structure and optimization. Thank you!

function prefixAAnToNumber($num) {
    $prefixAn = array(8, 11, 18, '8', '11', '18');
    $verAn = 'an ' . number_format($num);
    $verA = 'a ' . number_format($num);

    if (in_array($num,$prefixAn)) {
        return $verAn;
    } else if (strlen($num) &gt; 1) {
        $numComma = number_format($num);
        if (substr($numComma,0,1) == '8') {
            return $verAn;
        } else if (in_array(substr($numComma,0,2), $prefixAn) &amp;&amp; substr($numComma,2,1) == ',') {
            return $verAn;
        } else {
            return $verA;
        }
    } else {
        return $verA;
    }
}


Example usage:

$num = 11;
for ($i = 0; $i &lt; 10; ++$i) {
    echo '&lt;p&gt;'.$num.' -&gt; "';
    echo prefixAAnToNumber($num);
    echo ' kg shipment"&lt;/p&gt;';
    $num = $num * 10;
}


Output:

11 -&gt; "an 11 kg shipment"

110 -&gt; "a 110 kg shipment"

1100 -&gt; "a 1,100 kg shipment"

11000 -&gt; "an 11,000 kg shipment"

110000 -&gt; "a 110,000 kg shipment"

1100000 -&gt; "a 1,100,000 kg shipment"

11000000 -&gt; "an 11,000,000 kg shipment"

110000000 -&gt; "a 110,000,000 kg shipment"

1100000000 -&gt; "a 1,100,000,000 kg shipment"

11000000000 -&gt; "an 11,000,000,000 kg shipment"
Rather than having many return statements I would keep the logic that determines whether it should be 'a' or 'an' together.  I think it is actually easier to understand reading the ANDs and ORs than spread out if and else statements.

I prefer not to create temporary variables that are not used for anything - so I wouldn't create $verA and $verAn.  I do however create a variable for $numComma.  By having this we avoid calling number_format more than is necessary.

This is how it looks my way:

function prefixAAnToNumber($num)
{
    $prefixAn = array(8, 11, 18, '8', '11', '18');
    $numComma = number_format($num);

    if (in_array($num, $prefixAn) ||
    (strlen($num) &gt; 1 &amp;&amp;
     (substr($numComma, 0, 1) == '8' ||
      (in_array(substr($numComma, 0, 2), $prefixAn) &amp;&amp;
       substr($numComma, 2, 1) == ','))))
    {
        return 'an ' . $numComma;
    }

    return 'a ' . $numComma;
}