-2

I have the following code to find all the values of an array and echo them...

foreach($_POST as $result) {
     echo $result;
}

But I want to be able to find the name of the array item too such as...

foreach($_POST as $result) {
     echo "The value of $thing is $result";
}

Does this make any sense? Sorry

Thanks in advance,

Ben

Speedysnail6
  • 67
  • 1
  • 6
  • 4
    Please take a look at the [documentation](http://www.php.net//manual/en/control-structures.foreach.php) before heading to Stackoverflow. – Jonast92 Jun 18 '14 at 15:29

2 Answers2

4

This will put the array keys in $key and value in $value variables.

foreach($_POST as $key=>$value) {
   echo "The value of $key is $value";
}
Think Different
  • 2,815
  • 1
  • 12
  • 18
1

I'm assuming you mean the array key:

foreach($_POST as $thing => $result) {
     echo "The value of $thing is $result";
}

See the PHP foreach docs

Jim
  • 22,354
  • 6
  • 52
  • 80