Skip to content

@RalfAlbert /multi_checkbox.php
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Handling multiple checkboxes in an easy way
<?php
$mPost = array(
'action' => 'send',
'user' => 'Horst',
'a' => 'On',
'c' => 'On',
'foo' => 'bar',
'baz' => '',
);
$defaults = array(
'a' => '',
'b' => '',
'c' => '',
);
$data = array_merge( $defaults, $mPost );
$bin = '';
foreach( $defaults as $key => $val ){
$bin .= sprintf( '%b', !!$data[$key] );
//$bin .= ! empty( $data[$key] ) ? '1' : '0';
}
$dec = bindec( $bin );
var_dump( $bin );
var_dump( $dec );
switch( $bin ){
case '000':
//nichts ausgewaehlt
break;
case '100':
// nur checkbox 'a' wurde ausgewählt
break;
case '101':
// checkbox 'a' wurde ausgewaehlt, checkbox 'b' jedoch NICHT
break;
default:
// alle anderen Faelle
break;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.