I have a HTML form which looks like this...
<input type="checkbox" name="comp[{url_title}][check]" value="Yes" class="checkbox" />
{if question}<input type="text" name="comp[{url_title}][answer]" value="" />{/if}
<input type="checkbox" name="comp[{url_title}][check]" value="Yes" class="checkbox" />
{if question}<input type="text" name="comp[{url_title}][answer]" value="" />{/if}
<input type="checkbox" name="comp[{url_title}][check]" value="Yes" class="checkbox" />
{if question}<input type="text" name="comp[{url_title}][answer]" value="" />{/if}
my vardump on $_POST looks like this...
array(3) {
["some-competition-title"]=>
array(1) {
["check"]=>
string(3) "Yes"
}
["third-competition"]=>
array(2) {
["check"]=>
string(3) "Yes"
["answer"]=>
string(6) "asdasd"
}
["another-comp-title"]=>
array(1) {
["check"]=>
string(3) "Yes"
}
}
and my foreach loop looks like this
foreach ($_POST['comp'] as $topkey => $input) {
foreach ($input as $key => $value) {
echo "<div style=\"background:#fff; padding:10px;\">";
echo "$topkey | $value ";
echo "<br>";
echo "</div>";
}
}
which will return
some-competition-title | Yes
third-competition | Yes
third-competition | asdasd
another-comp-title | Yes
OK - I'm trying to pass the foreach loop so it will combine the checkbox and the answer if the name of the array (url-title) is the same, so essentially I would like it to return this.
some-competition-title | Yes
third-competition | Yes | asdasd
another-comp-title | Yes
Opposed to what I have above. Any help would be really appreciated. Thanks.