...

View Full Version : Help with FOREACH... with an example



Neno
12-10-2008, 08:17 PM
Ok, it must be that I am tired as I can not figure out the simple thing that I have done so many times. FOREACH.

In my simple example, all I want is to print out all the values from the array.


<form action="testarray.php" method="post">
<input type="text" name="toolname[]"><br />
<input type="text" name="toolname[]"><br />
<input type="text" name="toolname[]">
<input type="submit" name="submit" value="submit"></form>




$toolname = $_POST['toolname'];

print_r($toolname);

foreach ($toolname as $value) {
echo '<p>' . $toolname[$value] . '</p>';




The Array prints out fine but the foreach part doesn't work...

And I have no idea why my php code appears on one long line in this post, sorry.

PappaJohn
12-10-2008, 08:20 PM
$toolname = $_POST['toolname'];
print_r($toolname);
foreach ($toolname as $value)
{
echo '<p>' . $value . '</p>';
}

Neno
12-10-2008, 08:29 PM
LOL, I knew it was something real stupid that I overlooked. Oh well... told you I was tired.

Thanks a lot. :thumbsup:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum