Make array from checkbox form

后端 未结 8 1806
囚心锁ツ
囚心锁ツ 2020-12-09 11:42

My friend and I are making a website that compiles news stories based on your interests. Is there and easy way to take the checkbox data and make an array out of the selecte

8条回答
  •  离开以前
    2020-12-09 12:00

    The following is a general routine to handle array variables sent to a page, that are located among regular name/value variables.

    Example php:

    ';
    foreach($_REQUEST as $name => $value){
      if (is_array($value)) {
        echo "$name:
    "; // Assign array to something more mnemonic $items = $value; foreach ($items as $item) { echo " $item
    "; } } else { echo "$name: $value
    "; } } echo '
    '; ?>

    Example Markup:

    Pizza Toppings

    Example Output:

    customerName: John
    toppings:
      bacon
      cheese
    

提交回复
热议问题