2 Element Array

HOw can I set up an array with the following key, value pairs.

{123, "Bob"},{345,"Harry"},{234,"Sue"};

I want to be able to read the array, compare the id to a variable and if match display the name . My code attempt so far is:

char myArray[][2] = {
{123,"Bob"},
{345,"Harry"},
{234,"Sue"},

};
void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);

}

void loop() {

 for (int x = 0; x <= 2; x++) {
    int myID = 123;
    if (myID == myArray[x][0]) {
      Serial.println(myArray[x][1]);
    }
  }
}

The theory being that id 123 matches the first array record and displays Bob.

You can't have an array of mixed data types. You could have 2 arrays, search one for an id and use its index value to extract the corresponding name from the second array.

Try an array of struct.
Or an array of class.

What about if I was to make the id data a string by changing the array to store {"123","BoB"} then when doing the comparison change ID from int to string so I end up comparing two strings.

Would that work, and if so how would I declare the setup the array?

char myArray[][2] = {
{"123","Bob"},
{"345","Harry"},
{"234,""Sue"},

};

Array of struct would be better:

typedef struct keyAndValue_ {
   int key;
   char value[NAMELENMAX+1];
} keyAndValue_t;

keyAndValue_t myArray[] = {
   {123, "Bob"},
   {345, "Harry"}
};

  for (int x = 0; x <= sizeof(myArray)/sizeof(myArray[0]); x++) {
    if (myID == myArray[x].key) {
      Serial.println(myArray[x].value);
    }
  }

Thanks all for the help. westfw, that suggestion worked for what I'm wanting to do. Thanks.

Structures are very, very, useful. A lot of multi-dimensional and/or parallel array constructs are hold-overs from languages like Fortran and BASIC that didn't have anything more complicated than arrays...