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!

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. 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.