swtlbee Posted February 3, 2010 Share Posted February 3, 2010 I have a simple html drop down - example: <select name="dd1[ ]" multiple size="3"> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> </select> When I request the data I get my values 1 3 5 etc. However I need to get the last value to use the following code: foreach ($dd1 as $s) { if(!(end($ddl) == $s)){ $thisvalue= " not at the end just yet '" . $s . "'"; } else{ $thisvalue= " This is the last value selected '" . $s . "' "; } } echo ($whereFields); Because I believe the Name of the drop down is dd1[ ] the array is always 0 or 1 never incrementing. How can I get it to increment to get the last value in the array? Quote Link to comment https://forums.phpfreaks.com/topic/190817-drop-down-get-end-of-the-array-value/ Share on other sites More sharing options...
ChemicalBliss Posted February 3, 2010 Share Posted February 3, 2010 You want to get the last array item? use count(); Im sure you can figure out how to use that function to your purpose. -CB- ps: php.net/manual Quote Link to comment https://forums.phpfreaks.com/topic/190817-drop-down-get-end-of-the-array-value/#findComment-1006267 Share on other sites More sharing options...
swtlbee Posted February 3, 2010 Author Share Posted February 3, 2010 I've tried count and I get 0123 etc. that does not seem to be working for me and if I could figure it out I wouldn't be asking for help. I do need help in trying to figure out how to assign values to my array in the drop down to get the end value. Quote Link to comment https://forums.phpfreaks.com/topic/190817-drop-down-get-end-of-the-array-value/#findComment-1006282 Share on other sites More sharing options...
wildteen88 Posted February 3, 2010 Share Posted February 3, 2010 To get the last value from your array, use array_pop. Example $dd1 = $_POST['dd1']; $lastValue = array_pop($dd1); echo $lastValue; Quote Link to comment https://forums.phpfreaks.com/topic/190817-drop-down-get-end-of-the-array-value/#findComment-1006298 Share on other sites More sharing options...
swtlbee Posted February 3, 2010 Author Share Posted February 3, 2010 array_pop was exactly what I needed!!! THANK YOU!!! Quote Link to comment https://forums.phpfreaks.com/topic/190817-drop-down-get-end-of-the-array-value/#findComment-1006312 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.