Jump to content

Somebody explain this one line of code for me?


Chud37

Recommended Posts

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!

Link to comment
Share on other sites

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. 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.