[FX.php List] Can't locate value in array
Chris Hansen
chris at iViking.org
Thu Jul 3 12:31:43 MDT 2008
Steve,
Two thoughts:
1) I don't see $countryCode defined anywhere;
2) From looking at http://us3.php.net/manual/en/function.in-array.php
I'm wondering if your parameters in in_array() aren't in the wrong
order...
--Chris
On Jul 3, 2008, at 11:27 AM, Steve Winter wrote:
> Hi all,
>
> I conduct a search for a particular record in my database, which
> results in one found record (the way this system works, it can only
> find one record, and it will always find one record, but that’s by-
> the-by). One of the db fields is called Country, thus I end up with;
>
> $studentData['data'][$studentKey]['Country'][0]
>
> Which will usually contain the name of a country. I now need to
> convert this to the ISO 3309 country code. I already use these
> elsewhere, when I need to find the country from the code, so I have
> an array $countryList, of the form;
>
> $countryList = array ("AF" => "Afghanistan",
> "AL" => "Albania",
> "DZ" => "Algeria",
> "AS" => "American Samoa",
> "AD" => "Andorra",
> etc...
>
> Thus what I want to do is;
>
> if(in_array($countryCode, $studentData['data']
> [$studentKey]['Country'][0])) {
> $thisCountry = current(array_keys($countryList,
> $studentData['data'][$studentKey]['Country'][0]));
>
> All good you’d think... well the answer is sort of, when I make the
> call to the db, it doesn’t work... if I hard-code a value into the
> country field it does...
>
> For example, ff I do;
>
> echo $studentData['data'][$studentKey]['Country'][0];
>
> Then I see the country that I expect to (eg France), but the
> in_array does not work.
>
> If I insert the line;
>
> $studentData['data'][$studentKey]['Country'][0] =
> ‘France’;
>
> Then it is found...
>
> Anyone got any idea what’s going on here...? this is seriously doing
> my head in...!!
>
> Cheers
> Steve
>
>
> No virus found in this outgoing message.
> Checked by AVG.
> Version: 7.5.524 / Virus Database: 270.4.4/1531 - Release Date:
> 2/07/2008 7:02 p.m.
>
> _______________________________________________
> FX.php_List mailing list
> FX.php_List at mail.iviking.org
> http://www.iviking.org/mailman/listinfo/fx.php_list
More information about the FX.php_List
mailing list