[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

PHP echo array key

Posted on 2010-09-17
2
Medium Priority
?
333 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Simplify Your Workload with One Tool

How do you combat today’s intelligent hacker while managing multiple domains and platforms? By simplifying your workload with one tool. With Lunarpages hosting through Plesk Onyx, you can:

Automate SSL generation and installation with two clicks
Experience total server control

Question has a verified solution.

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

Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Without even knowing it, most of us are using web applications on a daily basis.  In fact, Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We generally confuse these web applications to…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
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

650 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