By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,949 Members | 921 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,949 IT Pros & Developers. It's quick & easy.

Multidimensional array: see if 1st key is available

P: n/a
Hi,

I've got an multidimensional array
$ret = $country_code[$countryCode][$langCode];

Now I want to see if $countryCode is even in that array, because if it's
not, it doesn't make many sense to look further for $langCode.

Eg.

$country_code = array('BE' =>
array ('en' => 'Belgium',
'nl' => 'BelgiŽ'),
'NL' =>
array ('en' => 'Netherlands',
'nl' => 'Nederland'),
);

Searching for 'BE' would make sense, but 'LP' wouldn't.

I already tried:
$arr = array($country_code['LP']);
if (sizeof($arr) == 0)
print "LP not found!"

But that doesn't seem to work :-s. Would sb have any suggestions?
Greetings,
Mattias

Jul 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"Mattias.Campe" <Ma******************************@UGent.be> wrote:
I've got an multidimensional array
$ret = $country_code[$countryCode][$langCode];

Now I want to see if $countryCode is even in that array, because if it's
not, it doesn't make many sense to look further for $langCode.


array_key_exists()

http://uk.php.net/manual/en/function...key-exists.php

HTH;
JOn
Jul 17 '05 #2

P: n/a
Jon Kraft wrote:
"Mattias.Campe" <Ma******************************@UGent.be> wrote:

I've got an multidimensional array
$ret = $country_code[$countryCode][$langCode];

Now I want to see if $countryCode is even in that array, because if it's
not, it doesn't make many sense to look further for $langCode.

array_key_exists()

http://uk.php.net/manual/en/function...key-exists.php


Perfect! Thx Jon!

Greetings,
Mattias

Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.