Skip to content

Commit

Permalink
New: Add Carbon.Array.isCountable
Browse files Browse the repository at this point in the history
  • Loading branch information
jonnitto committed Mar 2, 2023
1 parent 05a4ce9 commit d8b14f4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
19 changes: 19 additions & 0 deletions Classes/EelHelper/ArrayHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,25 @@ public function length($countableObject): int
return 0;
}

/**
* The method checks if the given object is countable
*
* @param mixed $countableObject
* @return boolean
*/
public function isCountable($countableObject): bool
{
if ($countableObject instanceof Countable) {
return true;
}

if (is_array($countableObject)) {
return true;
}

return false;
}

/**
* Returns a boolean if the array has a specific key
*
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,12 @@ Check if a variable is iterable and has items

**Return** The variable or `null` if it is empty or not an iterable

### `Carbon.Array.isCountable(variable)`

Check if the given variable is countable

**Return** The `true` or `false`

### `Carbon.Array.sortByItem(array, key, direction)`

- `array` (iterable|mixed) array with arrays to sort
Expand Down

0 comments on commit d8b14f4

Please sign in to comment.