Table of Contents

array_key

WMPRO, WMMINI FW >= 1.953 WMMEGA FW >= 2.0

Return the key for an array index

Description

string array_key ( array $array, int $index )

Parameters

$array: An array with key/value pairs

$index: The index for the array element (the first element is index 0)

Return Values

String containing the key name of the array element at the specified index

Example

Create an array with key value pairs, iterate through the array, print out all keys and their associated values

<pre><?
  $arr=array();
  $arr['name']="John";
  $arr['age']=30;
  $arr['status']=1;
 
  for ($i=0; $i < sizeof($arr); $i++) {
    $key=array_key($arr,$i);
    print("Key at Index ".$i." is ".$key." and value is ".$arr[$key]."\r\n");
  }
?></pre>

The above example will output:

Key at Index 0 is name and value is John
Key at Index 1 is age and value is 30
Key at Index 2 is status and value is 1

See Also

array() - Create an array, with optional values

array_keys() - Return keys for an array that has key/value pairs

sizeof() - Return the number of elements in an array

print_r() - Dump the contents of an array to the current output

uPHP Variable Types and Limits