How to print_r $_POST array?

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

I have following table.

相关标签:
11条回答
  • 2020-12-31 15:20
    <?php 
    
     foreach ($_POST as $key => $value) {
      echo '<p>'.$key.'</p>';
      foreach($value as $k => $v)
      {
      echo '<p>'.$k.'</p>';
      echo '<p>'.$v.'</p>';
      echo '<hr />';
      }
    
    } 
    
     ?>
    

    this will work, your first solution is trying to print array, because your value is an array.

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

    Came across this 'implode' recently.

    May be useful to output arrays. http://in2.php.net/implode

    echo 'Variables: ' . implode( ', ', $_POST);
    
    0 讨论(0)
  • 2020-12-31 15:25

    $_POST is already an array. Try this:

    foreach ($_POST as $key => $value) {
        echo "<p>".$key."</p>";
        echo "<p>".$value."</p>";
        echo "<hr />";
    } 
    
    0 讨论(0)
  • 2020-12-31 15:27

    The foreach loops work just fine, but you can also simply

    print_r($_POST);
    

    Or for pretty printing in a browser:

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

    Just:

    foreach ( $_POST as $key => $value) {
    
      echo "<p>".$key."</p>";
      echo "<p>".$value."</p>";
      echo "<hr />";
    
    } 
    
    0 讨论(0)
  • 2020-12-31 15:29

    Because you have nested arrays, then I actually recommend a recursive approach:

    function recurse_into_array( $in, $tabs = "" )
    {
        foreach( $in as $key => $item )
        {
            echo $tabs . $key . ' => ';
            if( is_array( $item ) )
            {
                recurse_into_array( $item, $tabs . "\t" );
            }
            else
            {
                echo $tabs . "\t" . $key;
            }
        }
    }
    
    recurse_into_array( $_POST );
    
    0 讨论(0)
提交回复
热议问题