Jump to content

Help with a book.


geotri314

Recommended Posts

Hello guys. I actually have a question about a small text from a book, i use to read so as to learn php. i have come with something i really dont understand. I dont know if i should be asking you this, since my question is more about learning php, than actually writing php, but i have no one else...

Ok, so the book gives this code:

 

echo '<input type="checkbox" value="' . $row['id'] . '" name="todelete[]">';

 

and says this:

 

The square brackets result in the creation of an array within $_POST that stores the contents of the value attribute of every checked checkbox in the form

 

My question is: how is this happening? i mean do i miss some html piece of info where value is assigned to the name of an input? This explanation along with this code is really frustrating. i dont really understand either what it means, or how it does this. Can anyone shed some light please? thank you for your time.

Link to comment
https://forums.phpfreaks.com/topic/208912-help-with-a-book/
Share on other sites

It's about this piece of code

name="todelete[]"

 

It means that if you create several checkboxes like that (this code is probably in a loop, isn't it?), you will then be able to use $_POST['todelete'] as an array, to see which id's have checkboxes ticked or not.

 

do something like this to see contents of $_POST['todelete'] array

var_dump($_POST['todelete']);

 

 

This is a bit of a magic that HTML/PHP does for you.

Link to comment
https://forums.phpfreaks.com/topic/208912-help-with-a-book/#findComment-1091245
Share on other sites

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.