/ LJCPHPCodeDoc / LJCCollectionLib / LJCCollectionBase / RetrieveItem


Parameters
$key - The element key.
$throwError - Indicates if an error should be thrown if the key is not found.

Returns

The object with the matching key value.

Syntax

PHP
protected function RetrieveItem($key, bool $throwError = true)

Retrieves 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;
   }
 
   // Retrieves the item by Key value.
   public function Retrieve($key, bool $throwError = true)
   {
     $retItem = $this->RetrieveItem($key, $throwError);
     return $retItem;
   }
 }
 
 // Retrieves the item by Key value.
 private static function RetrieveItem()
 {
   $names = new Names();
   $names->Add("First");
   $names->Add("Second");
   $names->Add("Third");
   $result = $names->Retrieve(0);
 
   // result:
   // First
 }

Copyright © Lester J. Clark and Contributors.
Licensed under the MIT License.