Php key
From w3cyberlearnings
Contents |
PHP function key
This function returns array key or index element of the current array position.
Syntax key
- array: array input
key(array);
Example 1
<?php $records = array('Alyssa' => 10, 'Emma' => 3, 'Landon' => 5); echo key($records); ?>
Output
Alyssa
Example 2
<?php $records = array('Alyssa' => 10, 'Emma' => 3, 'Landon' => 5); while ($name = current($records)) { echo key($records); echo '<br/>'; next($records); } ?>
Output
Alyssa Emma Landon
Related Links
- array_change_key_case
- array_chunk
- array_combine
- array_count_values
- array_diff_assoc
- array_diff_key
- array_diff_uassoc
- array_diff_ukey
- array_diff
- array_fill_keys
- array_fill
- array_filter
- array_flip
- array_intersect_assoc
- array_intersect_key
- array_intersect_uassoc
- array_intersect_ukey
- array_intersect
- array_key_ exists
- array_keys