Jiblob Posted March 13, 2007 Share Posted March 13, 2007 Hello, I have a set of checkboxes: - <form post="<?php $_SERVER['PHP_SELF']; ?>" action="post"> Option 1<input type="checkbox" name="fruit[]" value="pear"> Option 2<input type="checkbox" name="fruit[]" value="apple"> Option 3<input type="checkbox" name="fruit[]" value="grape"> Option 4<input type="checkbox" name="fruit[]" value="orange"> Option 5<input type="checkbox" name="fruit[]" value="tomato"> </form> How can I extract the numbers of them all in relation to the checkboxes. EG. Grape, (Option) 1 I want to be able to automatically number them without the need for naming them all individually (EG. name="fruit_apple") because I want to allow for unlimited numbers of them. Thanks, - Luke Link to comment https://forums.phpfreaks.com/topic/42432-checkbox-number/ Share on other sites More sharing options...
Barand Posted March 13, 2007 Share Posted March 13, 2007 <?php foreach ($_POST['fruit'] as $n=>$fruit) { $opt = $n+1; echo "$fruit (Option $opt)<br/>"; } Link to comment https://forums.phpfreaks.com/topic/42432-checkbox-number/#findComment-205848 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.