-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7b182f7
commit d6e5ebc
Showing
1 changed file
with
27 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace ArrayLookup; | ||
|
||
use Traversable; | ||
|
||
use function count; | ||
use function is_array; | ||
use function iterator_count; | ||
|
||
class Counter | ||
{ | ||
/** | ||
* @param array<int|string, mixed>|Traversable<int|string, mixed> $data | ||
*/ | ||
public static function count(iterable $data): int | ||
{ | ||
// php 8.1 compat | ||
if (is_array($data)) { | ||
return count($data); | ||
} | ||
|
||
return iterator_count($data); | ||
} | ||
} |