php8.5
Home/ Manual/ bson / iterator/ MongoDB\BSON\Iterator::key

MongoDB\BSON\Iterator::key

PHP function Edit on GitHub ✎

(mongodb >=1.16.0)

Returns the key of the current element

Description

MongoDB\BSON\Iterator::key(): string|int

Parameters Parameters

Return Values

Returns the key of the current element. When iterating a BSON document, the key will always be a string. When iterating a BSON array, the key will be an int.

Errors/Exceptions

  • Throws MongoDB\Driver\Exception\LogicException if the iterator is not valid.

See Also

  • Iterator::key

Source: reference/mongodb/bson/iterator/key.xml · from the official PHP manual (php/doc-en)