I am doing some study on arrays, and I am trying to resolve how to store the values of a foreach
loop into an array which I can then print_r()
.
My script works fine with the exception of the $array = foreach()...
And as you can see I called return;
to return the results to the $array
variable, but I am getting a parse error.
Here is my code so far:
<?php
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<input type="radio" name="DataNameOne" value="Value 1">
<input type="radio" name="DataNameTwo" value="Value 2">
<input type="radio" name="DataNameThree" value="Value 3">
<input type="submit" />
</form>
<?php
$array = foreach ($_POST as $key=>$value) {
if (stristr($key, "section")) {
$section = $value;
$section_name = $key;
return;
}
echo "Key is: $key and Valus is: $value";
}
echo "<pre>";
print_r($array);
echo "</pre>";
?>