Iladarsda Iladarsda - 6 months ago 30
PHP Question

How to print_r $_POST array?

I have following table.

<form method="post" action="test.php">
<input name="id[]" type="text" value="ID1" />
<input name="value[]" type="text" value="Value1" />
<hr />

<input name="id[]" type="text" value="ID2" />
<input name="value[]" type="text" value="Value2" />
<hr />

<input name="id[]" type="text" value="ID3" />
<input name="value[]" type="text" value="Value3" />
<hr />

<input name="id[]" type="text" value="ID4" />
<input name="value[]" type="text" value="Value4" />
<hr />

<input type="submit" />
</form>


And test.php file

<?php

$myarray = array( $_POST);
foreach ($myarray as $key => $value)
{
echo "<p>".$key."</p>";
echo "<p>".$value."</p>";
echo "<hr />";
}

?>


But it is only returning this:
<p>0</p><p>Array</p><hr />


What I'm doing wrong?

Answer
<?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.