Parameters
$key - The element key.
$throwError - Indicates if an error should be thrown if the key is not found.
Syntax
| PHP |
|
protected function DeleteItem($key, bool $throwError = true): void
|
Remove the item by Key value.
Example
| PHP |
// The strongly typed collection class.
class Names extends LJCCollectionBase
{
// Adds a string.
// This method makes a string collection strongly typed.
public function Add(string $text)
{
$retItem = $this->AddItem($text);
return $retItem;
}
// Remove the item by Key value.
public function Remove($key, bool $throwError = true)
{
$this->DeleteItem($key, $throwError);
}
// Retrieves the item by index.
public function RetrieveAtIndex($index)
{
$retItem = $this->RetrieveItemAtIndex($index);
return $retItem;
}
}
// Deletes an item.
public function DeleteItem()
{
$names = new Names();
$names->Add("First");
$names->Add("Second");
$names->Add("Third");
$this->Remove(0);
$result = $names->RetrieveItemAtIndex(0);
// result:
// Second
}
|
Copyright © Lester J. Clark and Contributors.
Licensed under the MIT License.