src/collections/Collection.php
public function find(callable $predicate, bool $findKeys = null, int $limit = 0): array
	{
		$data = [];
		$found = 0;
		
		if ($limit >= 0)
		{
			foreach ($this->data as $key => $value)
			{
				if ($predicate($value, $key) === true)
				{
					$found++;
					
					if ($findKeys === null)
					{
						$data[$key] = $value;
					}
					else
					{
						$data[] = $findKeys ? $key : $value;
					}
					
					if ($found === $limit)
					{
						break;
					}
				}
			}
		}
		else
		{
			// iterate in reverse rather than reversing the whole array or trimming all matches to the limit
			end($this->data);
			
			for ($i = 0; $i < count($this->data); $i++)
			{
				$key = $this->key();
				$value = $this->current();
				
				if ($predicate($value, $key) === true)
				{
					$found++;
					
					if ($findKeys === null)
					{
						$data[$key] = $value;
					}
					else
					{
						$data[] = $findKeys ? $key : $value;
					}
					
					if ($found === -$limit)
					{
						break;
					}
				}
				
				$this->prev();
			}
			
			$this->rewind();
			
			// entries need to be reversed otherwise they'll be in the wrong order
			$data = array_reverse($data, ($findKeys === null));
		}
		
		return $data;
	}
public function find(callable $predicate, bool $findKeys = null, int $limit = 0): array
	{
		$data = [];
		$found = 0;
		
		if ($limit >= 0)
		{
			foreach ($this->data as $key => $value)
			{
				if ($predicate($value, $key) === true)
				{
					$found++;
					
					if ($findKeys === null)
					{
						$data[$key] = $value;
					}
					else
					{
						$data[] = $findKeys ? $key : $value;
					}
					
					if ($found === $limit)
					{
						break;
					}
				}
			}
		}
		else
		{
			// iterate in reverse rather than reversing the whole array or trimming all matches to the limit
			end($this->data);
			
			for ($i = 0; $i < count($this->data); $i++)
			{
				$key = $this->key();
				$value = $this->current();
				
				if ($predicate($value, $key) === true)
				{
					$found++;
					
					if ($findKeys === null)
					{
						$data[$key] = $value;
					}
					else
					{
						$data[] = $findKeys ? $key : $value;
					}
					
					if ($found === -$limit)
					{
						break;
					}
				}
				
				$this->prev();
			}
			
			$this->rewind();
			
			// entries need to be reversed otherwise they'll be in the wrong order
			$data = array_reverse($data, ($findKeys === null));
		}
		
		return $data;
	}
public function find ( callable $ predicate , bool $ findKeys = null , int $ limit = 0 ) : array { $ data = [ ] ; $ found = 0 ; if ( $ limit >= 0 ) { foreach ( $ this -> data as $ key => $ value ) { if ( $ predicate ( $ value , $ key ) === true ) { $ found ++ ; if ( $ findKeys === null ) { $ data [ $ key ] = $ value ; } else { $ data [ ] = $ findKeys ? $ key : $ value ; } if ( $ found === $ limit ) { break ; } } } } else { // iterate in reverse rather than reversing the whole array or trimming all matches to the limit end ( $ this -> data ) ; for ( $ i = 0 ; $ i < count ( $ this -> data ) ; $ i ++ ) { $ key = $ this -> key ( ) ; $ value = $ this -> current ( ) ; if ( $ predicate ( $ value , $ key ) === true ) { $ found ++ ; if ( $ findKeys === null ) { $ data [ $ key ] = $ value ; } else { $ data [ ] = $ findKeys ? $ key : $ value ; } if ( $ found === - $ limit ) { break ; } } $ this -> prev ( ) ; } $ this -> rewind ( ) ; // entries need to be reversed otherwise they'll be in the wrong order $ data = array_reverse ( $ data , ( $ findKeys === null ) ) ; } return $ data ; }
Find all entries that match the given criteria.

@param callable $predicate : the callback function to use to find the match.
Callback signature - ($value, $key) => bool
@param bool $findKeys : if true, return an array containing only the matched keys; if false,
return matched values; and if NULL - return the original key => value pairs.
@param int $limit : maximum amount of keys to return. If positive, will return the first N keys, otherwise
the last N keys.
@return array an array containing the matches found
Find all entries that match the given criteria .