akshay Posted June 16, 2010 Share Posted June 16, 2010 Hello. I understand logic behind foreach ($_POST as $key) loop but what about: foreach ($_POST as $key => $value) I mean wha does => imply. Please explain with an example. Thank you! Link to comment https://forums.phpfreaks.com/topic/204930-logic-behind-foreach-_post-as-key-value/ Share on other sites More sharing options...
bugcoder Posted June 16, 2010 Share Posted June 16, 2010 an array is always consists of key value pair e.g $numericArray = array(1=>'apple',2=>'orange'); or $associativeArray = array('shoe'=>'abc','cloaths'=>'xyz') when we loop throw both then in $numericArray $key will be 1,2 and values will be apple and orange and in $associativArray $key will be shoe, cloaths and values will be abc and xyz you can do so foreach($anyArray as $key=>$value){ echo $key . ' = ' . $value; } Link to comment https://forums.phpfreaks.com/topic/204930-logic-behind-foreach-_post-as-key-value/#findComment-1072855 Share on other sites More sharing options...
akshay Posted June 16, 2010 Author Share Posted June 16, 2010 Thanks a lot Link to comment https://forums.phpfreaks.com/topic/204930-logic-behind-foreach-_post-as-key-value/#findComment-1072861 Share on other sites More sharing options...
Maq Posted June 16, 2010 Share Posted June 16, 2010 http://us2.php.net/manual/en/control-structures.foreach.php Link to comment https://forums.phpfreaks.com/topic/204930-logic-behind-foreach-_post-as-key-value/#findComment-1072989 Share on other sites More sharing options...
cliffem Posted October 25, 2014 Share Posted October 25, 2014 How could you perform some action on the original value of $value before reaching the $key => $value stage? ? foreach ($_POST as $key => $value) Comes from <input type="text" class="required" name="nombre" /> Need to convert the original value of $value to proper case. It is now being entered helter shelter lowe, mixd, all caps, etc. Link to comment https://forums.phpfreaks.com/topic/204930-logic-behind-foreach-_post-as-key-value/#findComment-1494726 Share on other sites More sharing options...
blacknight Posted October 25, 2014 Share Posted October 25, 2014 when you loop the array use php case functions to change it EX: strtolower($value) this make it all lower no matter what the user has entred Link to comment https://forums.phpfreaks.com/topic/204930-logic-behind-foreach-_post-as-key-value/#findComment-1494727 Share on other sites More sharing options...
mac_gyver Posted October 25, 2014 Share Posted October 25, 2014 don't hijack threads for your problem. topic locked. Link to comment https://forums.phpfreaks.com/topic/204930-logic-behind-foreach-_post-as-key-value/#findComment-1494730 Share on other sites More sharing options...
Recommended Posts