j.smith1981 Posted June 6, 2011 Share Posted June 6, 2011 I am trying to trim the values of a $_POST array like so: <?php if(array_key_exists('register', $_POST)) { foreach($_POST as $value) { trim($value); } } But then seeing if I can use another loop to see if anything has actually been entered, how would I go about doing this? Keep thinking of a better way of doing this but I am not too sure how. Any help's appreciated, Jeremy. Link to comment https://forums.phpfreaks.com/topic/238590-how-to-put-a-conditional-within-a-loop-what-a-user-has-entered/ Share on other sites More sharing options...
gizmola Posted June 6, 2011 Share Posted June 6, 2011 Before the if.. loop $foundpost = false; substitute for your trim()... if (!empty(trim($value)) $foundpost = true; Link to comment https://forums.phpfreaks.com/topic/238590-how-to-put-a-conditional-within-a-loop-what-a-user-has-entered/#findComment-1226079 Share on other sites More sharing options...
wildteen88 Posted June 6, 2011 Share Posted June 6, 2011 use array_map If you want apply trim() to all values within $_POST['register']; $register = array_map('trim', $_POST['register']); Link to comment https://forums.phpfreaks.com/topic/238590-how-to-put-a-conditional-within-a-loop-what-a-user-has-entered/#findComment-1226080 Share on other sites More sharing options...
j.smith1981 Posted June 7, 2011 Author Share Posted June 7, 2011 Ahh that's wonderful. Will have a crack with that, to see what else I can do with it, wonderful thank you so much. Really have to say this is the most impressive forum I have ever been on for PHP tips and tricks. I like the way within a few hours in the afternoon someone will reply with a good example of what to do and explaining a reason for this, if it seems quite confusing but those to me look very interesting. Love the way I am trying to go for more maintainable code, using a reference from memory of a book I have been reading on PHP and trying the examples out for myself. Thanks again, Jez. Link to comment https://forums.phpfreaks.com/topic/238590-how-to-put-a-conditional-within-a-loop-what-a-user-has-entered/#findComment-1226326 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.