jollydonkey
Technical User
Hello -
I'm hoping someone can help me as I'm relatively new to PHP.
In a nutshell, I would like to know the PHP version of the javascript code below (using arrays and looping). Essentially, I'm trying to capture related values from a form (there are 3 - APPLE, BEAR, and CAR), create a string by appending each related value separated by a comma (dropping the ending comma), and assigning the result to new variables.
I'm hoping there's a very elegant PHP solution - I just don't know what it would be and how to go about it. A working PHP solution would be greatly appreciated.
Thanks!
Jolly Donkey
I'm hoping someone can help me as I'm relatively new to PHP.
In a nutshell, I would like to know the PHP version of the javascript code below (using arrays and looping). Essentially, I'm trying to capture related values from a form (there are 3 - APPLE, BEAR, and CAR), create a string by appending each related value separated by a comma (dropping the ending comma), and assigning the result to new variables.
I'm hoping there's a very elegant PHP solution - I just don't know what it would be and how to go about it. A working PHP solution would be greatly appreciated.
Thanks!
Jolly Donkey
Code:
// written in javascript
var N = new Array();
var LOI = new Array();
var IR = new Array();
APPLE[0] = frmOpt1.opt1A1.value;
APPLE[1] = frmOpt1.opt1A2.value;
APPLE[2] = frmOpt1.opt1A3.value;
APPLE[3] = frmOpt1.opt1A4.value;
APPLE[4] = frmOpt1.opt1A5.value;
BEAR[0] = frmOpt1.opt1B1.value;
BEAR[1] = frmOpt1.opt1B2.value;
BEAR[2] = frmOpt1.opt1B3.value;
BEAR[3] = frmOpt1.opt1B4.value;
BEAR[4] = frmOpt1.opt1B5.value;
CAR[0] = frmOpt1.opt1C1.value;
CAR[1] = frmOpt1.opt1C2.value;
CAR[2] = frmOpt1.opt1C3.value;
CAR[3] = frmOpt1.opt1C4.value;
CAR[4] = frmOpt1.opt1C5.value;
var APPLEOutput = "";
var BEAROutput = "";
var CAROutput = "";
for (var counter = 0; counter < 5; counter++){
if (APPLE[counter] == ""){
APPLEOutput = APPLEOutput + APPLE[counter];
}
else {
APPLEOutput = APPLEOutput + APPLE[counter] + ", ";
}
if (BEAR[counter] == ""){
BEAROutput = BEAROutput + BEAR[counter];
}
else {
BEAROutput = BEAROutput + BEAR[counter] + ", ";
}
if (CAR[counter] == ""){
CAROutput = CAROutput + CAR[counter];
}
else {
CAROutput = CAROutput + CAR[counter] + ", ";
}
}
var APPLEFinal = APPLEOutput.substr(0,(APPLEOutput.length-2));
var BEARFinal = BEAROutput.substr(0,(BEAROutput.length-2));
var CARFinal = CAROutput.substr(0,(CAROutput.length-2));