PHP
- 2 ответа
- 0 вопросов
1
Вклад в тег
<form action="" method="get">
<input type="checkbox" name="checkbox_values[]" value="">
<input type="checkbox" name="checkbox_values[]" value="">
<input type="checkbox" name="checkbox_values[]" value="">
<input type="checkbox" name="checkbox_values[]" value="">
<input type="checkbox" name="checkbox_values[]" value="">
<input type="submit" value="Submit">
</form>
<?php
if(isset($_GET['checkbox_values']) && is_array($_GET['checkbox_values'])){
$checkbox_values = $_GET['checkbox_values'];
$res_string = '';
foreach ($checkbox_values as $index => $checkbox_value) {
switch($checkbox_value){
case '1':
$new_val = 'a';
break;
case '2':
$new_val = 'b';
break;
default:
$new_val = '';
}
$res_string .= $new_val;
//if not last array element add separator
if(end($checkbox_values) != $checkbox_value) $res_string .= ',';
}
}
?>