How to print_r $_POST array?

前端 未结 11 2109
我在风中等你
我在风中等你 2020-12-31 14:39

I have following table.

相关标签:
11条回答
  • 2020-12-31 15:32

    You are adding the $_POST array as the first element to $myarray. If you wish to reference it, just do:

    $myarray = $_POST;
    

    However, this is probably not necessary, as you can just call it via $_POST in your script.

    0 讨论(0)
  • 2020-12-31 15:34

    $_POST is already an array, so you don't need to wrap array() around it.

    Try this instead:

    <?php 
    
     for ($i=0;$i<count($_POST['id']);$i++) {
    
      echo "<p>".$_POST['id'][$i]."</p>";
      echo "<p>".$_POST['value'][$i]."</p>";
      echo "<hr />";
    
    } 
    
     ?>
    

    NOTE: This works because your id and value arrays are symmetrical. If they had different numbers of elements then you'd need to take a different approach.

    0 讨论(0)
  • 2020-12-31 15:34

    Why are you wrapping the $_POST array in an array?

    You can access your "id" and "value" arrays using the following

    // assuming the appropriate isset() checks for $_POST['id'] and $_POST['value']
    
    $ids = $_POST['id'];
    $values = $_POST['value'];
    
    foreach ($ids as $idx => $id) {
        // ...
    }
    
    foreach ($values as $idx => $value) {
        // ...
    }
    
    0 讨论(0)
  • 2020-12-31 15:36

    As you need to see the result for testing purpose. The simple and elegant solution is the below code.

    echo "<pre>";
    print_r($_POST);
    echo "</pre>";
    
    0 讨论(0)
  • 2020-12-31 15:44

    $_POST is an array in itsself you don't need to make an array out of it. What you did is nest the $_POST array inside a new array. This is why you print Array. Change it to:

    foreach ($_POST as $key => $value) {
    
      echo "<p>".$key."</p>";
      echo "<p>".$value."</p>";
      echo "<hr />";
    
    } 
    
    0 讨论(0)
提交回复
热议问题