473,395 Members | 1,458 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

array

1
How to print the keyname using array.is it possible?
Aug 1 '07 #1
4 871
nathj
938 Expert 512MB
How to print the keyname using array.is it possible?
If you have associative array called $laArray:

[php]
<?

$laArray['peter'] = 23;
$laArray['sarah'] = 25;
$laArray['steve'] = 27;
$laArray['ann'] = 52;
$laArray['andy'] = 55;

foreach($laArray as $key => $value)
{
echo "Key: $key; Value: $value <br />";
}
?>
[/php]

I believe that does the trick.

Cheers
nathj
Aug 1 '07 #2
Motoma
3,237 Expert 2GB
If you have associative array called $laArray:

[php]
<?

$laArray['peter'] = 23;
$laArray['sarah'] = 25;
$laArray['steve'] = 27;
$laArray['ann'] = 52;
$laArray['andy'] = 55;

foreach($laArray as $key => $value)
{
echo "Key: $key; Value: $value <br />";
}
?>
[/php]

I believe that does the trick.

Cheers
nathj
If that isn't good enough:

Expand|Select|Wrap|Line Numbers
  1.  
  2. $laArray['peter'] = 23;
  3. $laArray['sarah'] = 25;
  4. $laArray['steve'] = 27;
  5. $laArray['ann'] = 52;
  6. $laArray['andy'] = 55;
  7.  
  8. foreach($laArray as $value)
  9. {
  10.     echo "Key: ".key($value)."; Value: $value <br />";
  11. }
  12.  
Aug 1 '07 #3
djpaul
137 100+
or you can do:
[PHP]
$pietje = array ("hello", "car", "airplane");

print_r ($pietje['hello']);

[/PHP]
Displays:
[HTML]hello[/HTML]

Gr Paul
Aug 1 '07 #4
kovik
1,044 Expert 1GB
or you can do:
[PHP]
$pietje = array ("hello", "car", "airplane");

print_r ($pietje['hello']);

[/PHP]
Displays:
[HTML]hello[/HTML]

Gr Paul
... No. No it wouldn't. :-/

Motoma's suggestion to use the key() function is likely the correct answer.
Aug 2 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Brian | last post by:
I'm diddlying with a script, and found some behavior I don't understand. Take this snippet: for ($i = 0; $i <= count($m); $i++) { array_shift($m); reset($m); }
2
by: Stormkid | last post by:
Hi Group I'm trying to figure out a way that I can take two (two dimensional) arrays and avShed and shed, and subtract the matching elements in shed from avShed I've pasted the arrays blow from a...
58
by: jr | last post by:
Sorry for this very dumb question, but I've clearly got a long way to go! Can someone please help me pass an array into a function. Here's a starting point. void TheMainFunc() { // Body of...
104
by: Leszek | last post by:
Hi. Is it possible in javascript to operate on an array without knowing how mamy elements it has? What i want to do is sending an array to a script, and this script should add all values from...
7
by: Jim Carlock | last post by:
Looking for suggestions on how to handle bad words that might get passed in through $_GET variables. My first thoughts included using str_replace() to strip out such content, but then one ends...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.