tags:

views:

114

answers:

5
$arr['thisiskey'] = 1;

Like above,how to get "thisiskey" programmatically?

+8  A: 

Use array_keys:

$keys = array_keys($array);
var_dump($keys[0]);
Gumbo
Snap. You beat me...
brianreavis
A: 

foreach ($arr as $key => $value) { echo $key . PHP_EOL; }

r3zn1k
A: 
list($key, ) = each($arr);
print $key;
Anti Veeranna
A: 

Iteratively:

foreach ($array as $key => $value){

    print $key . ' = ' . $value .'\n';

}
Johhny Hive
+2  A: 

The simplest solution:

key($arr);

key returns current key of the array

doc