I have a bunch of checkboxes. I have to go through and build an array depending on which checkboxes are checked. The checkboxes are in a hierarchy, so the top boxes act as multpliers, meaning if a user selects location A & B then chooses subordinate checkboxes 1, 2, & 3 - the array yields:

A1
A2
A3
B1
B2
B3

When I look at this, it is screaming "Put me in a loop, and be done in 20 lines", but I can't seem to see how I can do this with a while loop...

Can anyone enlighten me?

//Create an array that will allow us to collect a combination of city & Location so that we can concatenate values
$text_array = array();


 //Check if each text box is checked, if it is, concatenate the city and location values collected on the previous page insert it into the next available index in our text
 //there will be text'X' where x = the number of checkboxes
if (isset($_POST['text1']))
{
    $text1  = $_SESSION['locations'][0];  //First city and location
    $text1 .= " ";                        //add a space
    $text1 .= $_POST['text1'];            //add text group e.g. "night clubs"
    $text_array[] = $text1;               //add item to list of texts to recieve
}
if (isset($_POST['text2']))
{
    $text2  = $_SESSION['locations'][0];
    $text2 .= " ";
    $text2 .= $_POST['text2'];
    $text_array[] = $text2;
}
if (isset($_POST['text3']))
{
    $text3  = $_SESSION['locations'][0];
    $text3 .= " ";
    $text3 .= $_POST['text3'];
    $text_array[] = $text3;
}
if (isset($_POST['text4']))
{
    $text4  = $_SESSION['locations'][0];
    $text4 .= " ";
    $text4 .= $_POST['text4'];
    $text_array[] = $text4;
}
 if (isset($_POST['text5']))
        {
            $text5  = $_SESSION['locations'][0];
            $text5 .= " ";
            $text5 .= $_POST['text5'];
            $text_array[] = $text5;
        }
        if (isset($_POST['text6']))
        {
            $text6  = $_SESSION['locations'][0];
            $text6 .= " ";
            $text6 .= $_POST['text6'];
            $text_array[] = $text6;
        }

if (!empty($_SESSION['locations'][1]))  //this checks if a second location was selected. Each City-location combination counts as one location
      {

    if (isset($_POST['text1']))
    {
        $text1  = $_SESSION['locations'][1];
        $text1 .= " ";
        $text1 .= $_POST['text1'];
        $text_array[] = $text1;
    }
    if (isset($_POST['text2']))
    {
        $text2  = $_SESSION['locations'][1];
        $text2 .= " ";
        $text2 .= $_POST['text2'];
        $text_array[] = $text2;
    }
    if (isset($_POST['text3']))
    {
        $text3  = $_SESSION['locations'][1];
        $text3 .= " ";
        $text3 .= $_POST['text3'];
        $text_array[] = $text3;
    }
    if (isset($_POST['text4']))
    {
        $text4  = $_SESSION['locations'][1];
        $text4 .= " ";
        $text4 .= $_POST['text4'];
        $text_array[] = $text4;
    }
     if (isset($_POST['text5']))
    {
        $text5  = $_SESSION['locations'][1];
        $text5 .= " ";
        $text5 .= $_POST['text5'];
        $text_array[] = $text5;
    }
    if (isset($_POST['text6']))
    {
        $text6  = $_SESSION['locations'][1];
        $text6 .= " ";
        $text6 .= $_POST['text6'];
        $text_array[] = $text6;
    }
}//end second location
    Write a Reply...