Basically I've got a list of checkboxes on my page, one of the checkboxes is labelled 'Other' and has a value of 'other'. Each checkbox name is "selection[]" and this is read in by the PHP script. The PHP script does the following: if($_POST['selection'] == null || count($_POST['selection']) > 3) Code (markup): and outputs an error if there are no checkboxes ticked or if there are more than 3 checkboxes ticked. I need the script to do the following: If any of the 'normal' checkboxes are ticked + the 'Other' checkbox is ticked, then the count() mustn't add the 'Other' checkbox to the count(). If no 'normal' checkboxes are ticked but the 'Other' checkbox is ticked then the count() functions as normal and has a value of 1. The catch however is that the 'Other' checkbox cannot have a different name to the rest, it must be "selection[]".
Try and give this a shot! i think this is what u need $arraystuff = $_POST['selection']; $counter = count($arraystuff); if ( array_search( "other", $arraystuff ) != false){ if ( ( $counter - 1 ) > 1 ) $counter-= 1; } echo $counter; Code (markup):
Cheers mate, I think that's working now. The only problem is that now it gives the following error when NO checkboxes have been ticked: "Warning: array_search() [function.array-search]: Wrong datatype for second argument" I know why it's saying that but do you know how I can fix this?
The variable $_POST['selection'] doesn't exist if no checkboxes have been selected so we could check for that <? if( isset($_POST['selection']) ) { $arraystuff = $_POST['selection']; $counter = count($arraystuff); if ( array_search( "other", $arraystuff ) != false){ if ( ( $counter - 1 ) >= 1 ) $counter-= 1; } }else $counter = 0; echo $counter; ?> Code (markup): also, please change the condition to "( $counter - 1 ) >= 1" small logical error..! that would still display count of both, if "other" and just one "normal" would be selected.. Cheers,