PHPverse 2025

Voting

: eight plus zero?
(Example: nine)

The Note You're Voting On

arne dot ludwig at posteo dot de
9 years ago
In response to gardnerjohng's note to retrieve the first _key_ of an array:

To retrieve the first _key_ of an array you can use the combination of reset() and key().

<?php
$properties
= array(
'colour' => 'grey',
'flavour' => 'rubber',
'name' => 'Mouse Ball',
'texture' => 'rubbery'
);

reset($properties);
echo
key($properties); // => 'colour'
?>

I prefer this solution as you don't have to create the keys array. This should (not measured) improve performance on large arrays.

<< Back to user notes page

To Top