[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

PHP echo array key

Posted on 2010-09-17
2
Medium Priority
?
355 Views
Last Modified: 2012-05-10
Hi Experts,

How can I echo the key of a key/value pair in an array.  For example:

array([part123]=>Available [part432]=>NotAvailable [part789]=>BackOrdered)

Let's say I want to echo in HTML both the key and the value, in this case the part number and the status but in different table <td>'s.

I can do the echoing and array handling.. but I can't remember how to specifically echo the key.

Any ideas?

Thanks,

HNM
0
Comment
Question by:HelpNearMe
2 Comments
 
LVL 11

Accepted Solution

by:
VanHackman earned 2000 total points
ID: 33705285
like this:
<?php

$a = array(
    "uno" => 1,
    "dos" => 2,
    "tres" => 3,
    "diecisiete" => 17
);

echo '<table border="1">';

foreach ($a as $key => $value)
{
	echo "<tr>";
    echo "\t<td>$a[$key]</td> <td>$value.</td>\n";
	echo "</tr>";
}

echo "</table>";

?>

Open in new window

0
 

Author Closing Comment

by:HelpNearMe
ID: 33705302
works for me ;)

Thanks,

HNM
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
Dramatic changes are revolutionizing how we build and use technology. Every company is automating, digitizing, and modernizing operations. We need a better, more connected way to work together as teams so we can harness the insights from our system…
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Suggested Courses
Course of the Month18 days, 6 hours left to enroll

831 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