-
-
Notifications
You must be signed in to change notification settings - Fork 0
Wiki Iterables
final class \FireHub\Core\Support\LowLevel\Iterables()
Important
This class is marked as final.
This class was created by Danijel Galić <danijel.galic@outlook.com>
Copyright: 2024 FireHub Web Application Framework
License: <https://opensource.org/licenses/OSL-3.0> OSL Open Source License version 3
Version: GIT: $Id$ Blob checksum.
Fully Qualified Class Name: \FireHub\Core\Support\LowLevel\Iterables
Source code: view source code
Blame: view blame
History: view history
Type | Name | Title |
---|---|---|
public static | count | ### Counts all elements in the array |
public static | current | ### Return the current element in an array |
public static | key | ### Fetch a key from an array |
public static | prev | ### Rewind the internal array pointer |
public static | next | ### Advance the internal pointer of an array |
public static | reset | ### Set the internal pointer of an array to its first element |
public static | end | ### Set the internal pointer of an array to its last element |
public static Iterables::count(array|\Countable $array, bool $multidimensional = false):int
Source code: view source code
Blame: view blame
- array or \Countable $array -
array<array-key, mixed>
Array to count. - bool $multidimensional = false - [optional] Count multidimensional items.
- int -
non-negative-int
Number of elements in an array.
public static Iterables::current(array $array):mixed
Warning
This function may return Boolean false, but may also return a non-Boolean value which evaluates to false. Please read the section on Booleans for more information. Use the === operator for testing the return value of this function.> [!NOTE] The results of calling current() on an empty array and on an array, whose internal pointer points beyond the end of the elements is indistinguishable from a bool false element. To properly traverse an array which may contain false elements, see the foreach control structure. To still use current() and properly check if the value is really an element of the array, the key() of the current() element should be checked to be strictly different from null.
Every array has an internal pointer to its "current" element, which is initialized to the first element inserted into the array.
Source code: view source code
Blame: view blame
- TKey of array-key
- TValue
- array $array -
array<TKey, TValue>
The array.
- mixed -
TValue|false
The current() function simply returns the value of the array element that is being pointed to with the internal pointer. It does not move the pointer in any way. If the internal pointer points beyond the end of the elements list or the array is empty, current() returns false.
public static Iterables::key(array $array):null|int|string
Key returns the index element of the current array position.
Source code: view source code
Blame: view blame
- TKey of array-key
- TValue
- array $array -
array<TKey, TValue>
The array.
- null or int or string -
TKey|null
The key() function simply returns the key of the array element that's currently being pointed to by the internal pointer. It does not move the pointer in any way. If the internal pointer points beyond the end of the elements list or the array is empty, key() returns null.
public static Iterables::prev(array &$array):mixed
Warning
This function may return Boolean false, but may also return a non-Boolean value which evaluates to false. Please read the section on Booleans for more information. Use the === operator for testing the return value of this function.> [!NOTE] The beginning of an array is indistinguishable from a bool false element. To make the distinction, check that the key() of the prev() element is not null.
Method prev() behaves just like next(), except it rewinds the internal array pointer one place instead of advancing it.
Source code: view source code
Blame: view blame
- TKey of array-key
- TValue
- by reference array $array -
array<TKey, TValue>
The input array.
- mixed -
TValue|false
Returns the array value in the previous place that's pointed to by the internal array pointer, or false if there are no more elements.
public static Iterables::next(array &$array):mixed
Warning
This function may return Boolean false, but may also return a non-Boolean value which evaluates to false. Please read the section on Booleans for more information. Use the === operator for testing the return value of this function.> [!NOTE] The end of an array is indistinguishable from a bool false element. To properly traverse an array which may contain false elements, see the foreach function. To still use next() and properly check if the end of the array has been reached, verify that the key() is null.
Method next() behaves like current(), with one difference. It advances the internal array pointer one place forward before returning the element value. That means it returns the next array value and advances the internal array pointer by one.
Source code: view source code
Blame: view blame
- TKey of array-key
- TValue
- by reference array $array -
array<TKey, TValue>
The array being affected.
- mixed -
TValue|false
Returns the array value in the next place that's pointed to by the internal array pointer, or false if there are no more elements.
public static Iterables::reset(array &$array):mixed
Warning
This function may return Boolean false, but may also return a non-Boolean value which evaluates to false. Please read the section on Booleans for more information. Use the === operator for testing the return value of this function.> [!NOTE] The return value for an empty array is indistinguishable from the return value in case of an array which has a bool false first element. To properly check the value of the first element in an array which may contain false elements, first check the count() of the array, or check that key() is not null, after calling reset().
Method reset() rewinds array's internal pointer to the first element and returns the value of the first array element.
Source code: view source code
Blame: view blame
- TKey of array-key
- TValue
- by reference array $array -
&array<TKey, TValue>
The input array.
- mixed -
TValue|false
Returns the value of the first array element, or false if the array is empty.
public static Iterables::end(array &$array):mixed
Warning
This function may return Boolean false, but may also return a non-Boolean value which evaluates to false. Please read the section on Booleans for more information. Use the === operator for testing the return value of this function.
Method end() advances array's internal pointer to the last element, and returns its value.
Source code: view source code
Blame: view blame
- TKey of array-key
- TValue
- by reference array $array -
&array<TKey, TValue>
The input array.
- mixed -
TValue|false
Returns the value of the last element or false for an empty array.
Build with phpDocumentor using template FireHub phpDocumentor Wiki Template.