foreach: showing name AND value

Posted on 2007-10-18
Last Modified: 2007-10-18

The problem with this is that it ONLY shows the value.

      foreach ($_POST as &$key) {
      echo $key ."/n";

I want to ALSO show the name of the post value.

If this is in my form:
  <input type="hidden" name="food" value="apple" />

Then I want this to be returned:

      food: apple

NOT just "apple"

I use PHP5
Question by:hankknight
    LVL 24

    Accepted Solution

    foreach ($_POST as $key=>$value)
    LVL 8

    Expert Comment

    foreach (array_keys($_POST) as &$key) {
          echo $key ."/n";
          echo $_POST[$key]."/n";

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    Introduction Many web sites contain image galleries; a common design for these galleries includes a page with a collection of thumbnail images.  You can click on each of the thumbnail images to see the larger version of the image.  This is easily i…
    I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now