secexists: $section_exists
subcatexists: $subcategory_exists
"; // While the array-key exists, this loop will run and collect all checkboxes // in the array called categories for($w=1;$w<500;$w++) { if(!array_key_exists('subcat_'.$w.'_1_1', $_POST)) { //$w = -1; break; } for($x=1;$x<500;$x++) { if(!array_key_exists('subcat_1_'.$x.'_1', $_POST)) { //$x = -1; break; } for($y=1;$y<500;$y++) { if(!array_key_exists('subcat_1_'.$x.'_'.$y, $_POST)) { // $y = -1; break; } $categories[$w][$x][] = $y; } } } // Now you have an array with all checkboxes, something like // $subcat[1][1][1] = The number of the first checked checkbox in the first category // $subcat[1][1][2] = The number of the second checked checkbox in the first category and so on. // $subcat[1][2][1] = The number of the first checked checkbox in the second category // $subcat[1][2][2] = The number of the second checked checkbox in the second category and so on. // $subcat[2][1][1] = The number of the first checked checkbox in the first category, second section // $subcat[2][1][2] = The number of the second checked checkbox in the first category, second section and so on. $key_exists = true; $subkey_exists = true; $strings = array(); // Loops through and turns all categories' arrays into strings for($h=1;$h<500;$h++) { if(!array_key_exists($h, $categories)) { //$key_exists = false; break; } if (!array_key_exists(1, $categories[$h])) { //$key_exists = false; break; } for($i=1;$i<500;$i++) { if(!array_key_exists($i, $categories[$h])) { //$subkey_exists = false; break; } print(sizeof($strings)); // This will turn the array into a string with all subcategories, separated by ;. // For example, 0;3;53 if subcategory 0, 3 and 53 are checked $strings[$h][$i] = implode(';', $categories[$h][$i]); } } // Now strings[] contains all the strings (like 1;3;5 and 3;5;7). Loop through the array: for($x=1;$x