I'm developing a room booking system using PHP for a school project.
I'm trying to create a variable name by concatenating values from two arrays together. here are the two arrays:
$day = array('Mon', 'Tue', 'Wed', 'Thu', 'Fri');
$B = array('P1B', 'P2B', 'P3B', 'P4B', 'P5B', 'P6B');
and then here is the code I'm currently using to try concatenate them:
// getting all the values from the table using $_POST. There are 120 different values so it is best to create these variables using a procedure
for ($l = 0; $l < count($day); ++$l) {
for ($k = 0; $k < count($B); ++$k) {
$days = $day[$l];
$week = $B[$k];
${$days . $week} = $_POST["'" . $days.$week . "'"];
};
};
Is the syntax of the concatenated variable correct? Is there a better way of doing this?
The final variable names of the concatenated variable should look something like:
$MonP1B
$MonP2B
$MonP3B
$MonP4B
$MonP5B
$MonP6B
$TueP1B
etc.