Posted by Jerry Stuckle on 04/15/06 05:57
Jack E Leonard wrote:
> I'm looping through the keys and values of a form submission using
>
> foreach($_POST as $key => $value)
> echo "$key = $value<br>";
>
> No problems there. All works as expected. But seveal of the values are
> arrays and the echo comes out like:
>
> subjectone = Array
> subjecttwo = Array
>
> There could be as many as 9 elements in each array but there may be as
> few as one. How can I get those $value that are arrays to echo the
> entire array using a foreach loop? I would like to end up with all
> values printed in the page whether in an array or not.
>
> Thanks
Or, alternatively, a recursive function will go all the way down the list:
function print_array($array) {
if (is_array($array)) {
foreach($array as $key => $value) {
echo $key . " ";
print_array($value);
}
}
else
echo $value . "<br>\n";
}
Tailor to suit your needs.
foreach($_POST as $key => $value) {
if (is_array($value))
echo "$key = $value<br>";
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
[Back to original message]
|