PHP pass and receive two dimensional array from form

后端 未结 1 1800
误落风尘
误落风尘 2021-01-15 00:45

I am trying to pass two paired variables, a category and its id for multiple user-created categories from a webform to a file for processing. I want to keep them linked so

相关标签:
1条回答
  • 2021-01-15 01:09

    good and single syntax for creating two dimensional array;

      <input type="text" name="cat[]" value="cat1">
      <input type="text" name="cat[]" value="cat2">
        ...
    

    While receiving cats;

    echo $_POST['cat'][0] // echoes cat1
    echo $_POST['cat'][1] // echoes cat2
    

    Further example;

    According to this definition,

    <input type="text" name="cat[$cat][$id]" value="cat1">
    
    foreach ($_POST['cat'] as $a=>$b){
        // $a == $cat
        foreach($b as $c=>$d) {
           // $c == $id
        }
    }
    
    0 讨论(0)
提交回复
热议问题