Skip to content

Instantly share code, notes, and snippets.

@galvao
Created August 13, 2022 19:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save galvao/3a08dfc46191674f26f77730b754fd71 to your computer and use it in GitHub Desktop.
Save galvao/3a08dfc46191674f26f77730b754fd71 to your computer and use it in GitHub Desktop.
The most convoluted way of counting the entries in a collection?
<?php
/**
* Given a collection that implements the Iterator interface:
* @see https://www.php.net/manual/en/class.iterator
*/
return (int)!empty($collection->entries) * ($collection->key() + 1);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment