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?
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>";
<?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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With