Chud37 Posted December 5, 2010 Share Posted December 5, 2010 I looked up 'how to get all POST variables' and I ended up putting this bit of code together. Im not experienced at all with OOP programming, but I think that when '=>' is used its to do with OOP? Anyway. I dont get this code. I understand Foreach $_POST, as $someVar, (BTW im looking for checkboxes from a form), However, If I leave out the '=> $val' I simply get a lot of 'on' values, indicating the checkboxes I checked. However, WITH the '=> $val' I end up with the checkbox name. Now i've changed the name of '$val' so i know its not a keyword. But i dont get it. Is there a way to access the value of the checkbox? Can someone explain to me whats going on here? I know that I can get the value of the checkbox by $_POST['$checkRows'] But, I have a feeling It can be done in the foreach line. foreach($_POST as $checkRows => $hip) { echo "POSTED: $checkRows<br>\n"; } Please help! Quote Link to comment https://forums.phpfreaks.com/topic/220771-somebody-explain-this-one-line-of-code-for-me/ Share on other sites More sharing options...
gizmola Posted December 5, 2010 Share Posted December 5, 2010 When you use foreach, you specify the variables that will receive the name of the array key, and the value of the array element. foreach (array as $arraykey => $element value) You are echoing out the key, rather than the value. If you change your echo to: echo "POSTED: $checkRows = $hip \n"; I think it will be clearer to you. Quote Link to comment https://forums.phpfreaks.com/topic/220771-somebody-explain-this-one-line-of-code-for-me/#findComment-1143408 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.