I have a series of values in an array called $arrayvali, which I want to send through a hidden field called rg[ps], in a form using post, at first I have not included the enctype inside the form because I don't know if this influences or not, I think that rather it is for image upload sending issues but well, I don't know if it should be included or not, the fact is that if the values that I have in the array are 1,2,3 what What I wanted is that when the form was sent through post, well, those values would be displayed, it would only be that, but there is no way, I don't know why I always get the word Array, so that is basically the objective, I have even tried to put the field rg[ps] like rg[ps][] or even change the name to rg alone or to rg[], the truth is I tried to do a lot of things and no way, finally I leave you the example and I hope you can help me,Thank you
<?php
if($_POST['send']=="ok")
{
foreach($_POST['rg'] as $key=>$val)
{
echo $val;
}
}
?>
<form action="" name="format" method="post" enctype="multipart/form-data" >
<?php
$arrayvali=array("casa","puerta","mesa");
?>
<input type="hidden" name="send" value="ok">
<input type="hidden" name="rg[ps]" value="<?php echo $arrayvali;?>">
<input type="submit" name="sender" value="sends">
</form>
If what you want is to pass the entire array in a single field without traversing it, you must Serialize the array or convert it to Json
Convert it to Json
To get the value in the post
serializing it
To get the value in the post
If what you want is to pass each value of the array in a separate field.
To get the value in the POST
If when submitting the form you want to get
$_POST['rg']
an array with the values of the array in the variable$arrayvali
, then what you could do is loop through the array$arrayvali
and create one<input name="rg[]"
for each value.Example: