ListItem
in package
Class ListItem
This class handles array manipulation.
Tags
Table of Contents
- $datas : array<string|int, mixed>
- $source : string
- assign() : mixed
- Assigns multiple items to the data array.
- clear() : mixed
- Clears all data.
- count() : int
- Retrieves the total number of items.
- delete() : bool
- Deletes the specified item.
- firstItem() : mixed
- Retrieves the first item in the array.
- get() : mixed
- Retrieves the value at the specified key.
- indexOf() : mixed
- Searches for a value in the array.
- init() : mixed
- Initializes the class with default values.
- insert() : mixed
- Inserts a new item after the specified key.
- insertBefore() : mixed
- Inserts a new item before the specified key.
- items() : array<string|int, mixed>
- Retrieves all items.
- keys() : array<string|int, mixed>
- Retrieves the list of keys.
- lastItem() : mixed
- Retrieves the last item in the array.
- loadFromFile() : static
- Loads the array from a file.
- saveToFile() : bool
- Saves the array to a file.
- set() : mixed
- Sets a value at the specified key.
- values() : array<string|int, mixed>
- Retrieves all values.
- arrayToString() : string
- Converts an array to a string.
Properties
$datas
public
array<string|int, mixed>
$datas
The data.
$source
private
string
$source
The source file path.
Methods
assign()
Assigns multiple items to the data array.
public
assign(array<string|int, mixed> $array) : mixed
Parameters
- $array : array<string|int, mixed>
-
The data to assign.
Return values
mixed —clear()
Clears all data.
public
clear() : mixed
Return values
mixed —count()
Retrieves the total number of items.
public
count() : int
Return values
int —The total number of items.
delete()
Deletes the specified item.
public
delete(string $key) : bool
Returns true if successful, false if not found.
Parameters
- $key : string
-
The key of the item to delete.
Return values
bool —True if the item is deleted successfully, false otherwise.
firstItem()
Retrieves the first item in the array.
public
firstItem() : mixed
Return values
mixed —The first item.
get()
Retrieves the value at the specified key.
public
get(string $key) : mixed
Returns the item at the key if found, null otherwise.
Parameters
- $key : string
-
The key to retrieve.
Return values
mixed —The item at the key, or null if not found.
indexOf()
Searches for a value in the array.
public
indexOf(mixed $value) : mixed
Returns the key of the found item if found, false otherwise.
Parameters
- $value : mixed
-
The value to search for.
Return values
mixed —The key of the found item, or false if not found.
init()
Initializes the class with default values.
public
init(array<string|int, mixed> $config) : mixed
Parameters
- $config : array<string|int, mixed>
-
The configuration values.
Return values
mixed —insert()
Inserts a new item after the specified key.
public
insert(mixed $key, mixed $item) : mixed
Parameters
- $key : mixed
-
The key after which the new item will be inserted.
- $item : mixed
-
The new item.
Return values
mixed —insertBefore()
Inserts a new item before the specified key.
public
insertBefore(mixed $key, mixed $item) : mixed
Parameters
- $key : mixed
-
The key before which the new item will be inserted.
- $item : mixed
-
The new item.
Return values
mixed —items()
Retrieves all items.
public
items() : array<string|int, mixed>
Return values
array<string|int, mixed> —The array of items.
keys()
Retrieves the list of keys.
public
keys() : array<string|int, mixed>
Return values
array<string|int, mixed> —The array of keys.
lastItem()
Retrieves the last item in the array.
public
lastItem() : mixed
Return values
mixed —The last item.
loadFromFile()
Loads the array from a file.
public
loadFromFile(string $file) : static
Parameters
- $file : string
-
The file path to load, including the path.
Return values
static —saveToFile()
Saves the array to a file.
public
saveToFile() : bool
Return values
bool —True if the array is successfully saved, false otherwise.
set()
Sets a value at the specified key.
public
set(string $key, mixed $value) : mixed
Parameters
- $key : string
-
The key to set.
- $value : mixed
-
The value to set.
Return values
mixed —values()
Retrieves all values.
public
values() : array<string|int, mixed>
Return values
array<string|int, mixed> —The array of values.
arrayToString()
Converts an array to a string.
private
arrayToString(int $indent, array<string|int, mixed> $array) : string
Parameters
- $indent : int
-
The indentation level.
- $array : array<string|int, mixed>
-
The array to convert.
Return values
string —The string representation of the array.