Using Array and Function in Arduino Mega

Hi all,
I'm working on a project in which i have to control several relays on press of button due to high volume of relays i want to configure Arduino pins and relay combination using Arrays and Functions code for same mentioned below...

//................Button Configuration State..............//

const int Mode1Button = 41;
const int Mode2Button = 42;
const int Mode3Button = 43;

//.................Defining Relays.........................//

const int FanRelays[] ={0, 1, 2, 3, 4, 5, 6, 7};
const int Lightelays[] ={14, 15, 16, 17, 18, 19, 20, 21};
const int SensorRelays[] ={23, 25, 27, 29, 31, 33, 35, 37};

int Mode1State = 0;
int Mode2State = 0;
int Mode3State = 0;



void setup() {
  // put your setup code here, to run once:

 pinMode(FanRelays[0, 1, 2, 3, 4, 5, 6, 7], OUTPUT);
 pinMode(DamperRelays[11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21], OUTPUT);
 pinMode(RdxRelays[23, 25, 27, 29, 31, 33, 35, 37], OUTPUT);


//................Activating internal pull-up resistor of Arduino Ports...............//

  pinMode(Mode1Button, INPUT_PULLUP);
  pinMode(Mode2Button, INPUT_PULLUP); 
  pinMode(Mode3Button, INPUT_PULLUP);

}

void loop() {
  // put your main code here, to run repeatedly:

  Mode1State = digitalRead(Mode1Button);
  Mode2State = digitalRead(Mode2Button);
  Mode3State = digitalRead(Mode3Button);


  if (Mode1State == LOW){
    OpenMode();
  }

  else if (Mode2State == LOW){
    CloseMode();
  }

  else if (Mode3State == LOW){
    EmergMode();
  }

  else {
    AllLow();
  }
}


//.....................Subroutines for Modes Executions..........................//

  void AllLow(){
    digitalWrite(FanRelays[0, 1, 2, 3, 4, 5, 6, 7], HIGH);
    digitalWrite(LightRelays[11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21], HIGH);
    digitalWrite(SensorRelays[23, 25, 27, 29, 31, 33, 35, 37], HIGH);
  }

  void OpenMode(){
    digitalWrite(FanRelays[0, 1, 2, 3, 4, 5, 6, 7], LOW);
  }

  void CloseMode(){
    digitalWrite(LightRelays[11, 12, 13, 14, 15, 16, 17, 18], LOW);
  }

  void EmergMode(){
    digitalWrite(SensorRelays[23, 25, 27, 29, 31, 33, 35, 37], LOW);
  }

Now above code is not working as per my requirement only pin0 is getting On and Off whichever switch is pressed , please guide me whether I'm using array and functions correctly?? As there is many different combinations and it become unmanageable if i don't control pins without using Arrays or Functions.
Also for security purpose i want that whenever one button is pressed all other buttons become inactive and become only active when button that i pressed is switched off, how can i achieve this?
Please help or guide me..
Thanks

m7nab:
pinMode(FanRelays[0, 1, 2, 3, 4, 5, 6, 7], OUTPUT);

This will not work, you must call pinMode 8 times, once for each element of FanRelays:

pinMode(FanRelays[0], OUTPUT);
pinMode(FanRelays[1], OUTPUT);
 ... etc. (or use a for loop)

The same goes for all lines like this:

digitalWrite(FanRelays[0, 1, etc.

PS.: Better not use digital pins 0 and 1, they are sort-of reserved for the serial port (RX/TX).

Hey thanks u so much for quick response after going through your recommendation and searching some internet I have modified code as below…

//.................Defining Relays.........................//

const int FanRelays[] ={0, 1, 2, 3, 4, 5, 6, 7};
const int Lightelays[] ={14, 15, 16, 17, 18, 19, 20, 21};
const int SensorRelays[] ={23, 25, 27, 29, 31, 33, 35, 37};

int PinCount = 8;
 for (int RelayPin = 0; RelayPin < PinCount; RelayPin++){
  pinMode(FanRelays[RelayPin], OUTPUT);
  pinMode(LightRelays[RelayPin], OUTPUT);
  pinMode(SensorRelays[RelayPin], OUTPUT);
  }
void AllLow(){
    for (int RelayPin = 0; RelayPin < PinCount; RelayPin++){
    digitalWrite(FanRelays[RelayPin], HIGH);
    digitalWrite(LightRelays[RelayPin], HIGH);
    digitalWrite(SensorRelays[RelayPin], HIGH);
    }
  }

  void OpenMode(){
    for (int RelayPin = 0; RelayPin < PinCount; RelayPin++){
    digitalWrite(FanRelays[RelayPin], LOW);
    }
  }

is it correct now ? But i have one question why we use loops or control individually why don’t we can use as earlier?
Also I have GPIO limitation that’s why i have to use pin0 & 1 what could go wrong if I use it as Digital Pin?

Also I have GPIO limitation that’s why i have to use pin0 & 1 what could go wrong if I use it as Digital Pin?

At some point you nay need to debug your code. The best debugging tool that you have with the Arduino IDE is Serial prints to monitor program flow and variable values. The Serial port uses pins 0 and 1. If you need more digital pins, be aware that the analog inputs can also be used as digital pins (the analog pins are actually digital pins with analog input as a special function).

Yeah. i'm using analog pins also as digital pins in my arduino, as project requirement is too big that i don't want to complicate code using other Arduino.

Then there are ways to get more digital pins without resorting to another Arduino. The MCP23008 and MCP23017 I2C expander chips give you another 8 or 16 bidirectional GPIO pins per chip. There are SPI versions of those chips, as well (MCP23S08 and MCP23D17). Another alternative is the shift register chips like the 74LS595.