Multidimensional array: see if 1st key is available

Ask a Question related to PHP Development, Design and Development.

  1. #1

    Default Multidimensional array: see if 1st key is available

    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

    Mattias.Campe Guest

  2. Similar Questions and Discussions

    1. creating a multidimensional array
      How can I combine two arrays in cfscript to form one multidimensional array? For example, I have two arrays: firstarray=fred; firstarray=jim;...
    2. Problem with multidimensional array
      Hi! I'm new on this forum, and in the Macromedia Flash development. I've read some books, like the Flash MX 2004 game development (C. S. Murray,...
    3. copying a multidimensional array
      Hi: whatz the best way to copy an multidimensional array onto another. I have never used something like clone, just want to know whatz the easiest...
    4. Split multidimensional array into 4 multidimensional arrays
      Hello everyone, I have a multidimensional array that I need to split into 4 multidimensional arrays. I've tried the examples from the...
    5. Sorting a Multidimensional Array
      I have an array like this: $events = array( array( '2003-07-01', 'Event Title 1', '1' //ID Number (not unique) ), array( '2003-07-02',
  3. #2

    Default Re: Multidimensional array: see if 1st key is available

    "Mattias.Campe" <MattiasDotNoSpamPlzThankYouCampe@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()

    [url]http://uk.php.net/manual/en/function.array-key-exists.php[/url]

    HTH;
    JOn
    Jon Kraft Guest

  4. #3

    Default Re: Multidimensional array: see if 1st key is available

    Jon Kraft wrote:
    > "Mattias.Campe" <MattiasDotNoSpamPlzThankYouCampe@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()
    >
    > [url]http://uk.php.net/manual/en/function.array-key-exists.php[/url]
    Perfect! Thx Jon!

    Greetings,
    Mattias

    Mattias.Campe Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139