On Tue, Nov 3, 2009 at 9:26 AM, Jordan Schatz <[email protected]> wrote:
> Anyone else have this experience? I generally don't have to typecast
> before a comparison, but in_array seems to require it?
I like really simple code.
<?php
//Test Data
$primary_phone = '18017848218';
// Load the zip code information
$area_codes = file('./area_codes',FILE_IGNORE_NEW_LINES);
$area_code = substr($primary_phone, 1, 3);
//Doesnt Work
if (!in_array($area_code, $area_codes)) {
$error_message = 'PLEASE ENTER A VALID PHONE NUMBER!';
$commit = 0;
}
Reading in the file using file()
http://www.php.net/manual/en/function.file.php will automatically put
the lines into an array, but also the flag passed will auto-chop the
newlines at the end, which is what is causing your type casting
problems.
--lonnie
_______________________________________________
UPHPU mailing list
[email protected]
http://uphpu.org/mailman/listinfo/uphpu
IRC: #uphpu on irc.freenode.net