简体   繁体   中英

How to get checkbox values in array in PHP?

I have an image upload form that looks like this: 图库截图

The code to generate tag checkboxes:

foreach($tag as $tagid => $tagname) {
  echo "<label><input type=\"checkbox\" name=\"img_tags[]\" value=\"".$tagid."\">".$tagname."</label>";
}

Then in PHP I want to read values of this checkboxes for each image. I want img_tags to be 2D array so I can loop over it and check values for each picture. Is this possible?

Output of:

$img_tags = $_POST['img_tags'];↵
foreach($img_tags as $t) {↵
    print_r($t);↵
}↵

is: 12121, which I don't understand at all.

如果要在$_POST变量中使用2d数组,则需要在名称中表示该数组。

name="img_tags[level_1_key][]"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM