Core Function Search

From Sputnik Wiki
Revision as of 11:16, 28 April 2012 by UberFoX (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
Grep( <array>, <pattern>, <flag> )

Contents

Description

Returns a new array consisting of the elements of the input array that match the given regex pattern.

Parameters

array

The array to use.

pattern

A regular expression pattern to use.

flag

Optional; If the flag is higher than 0 the search will be inverted and everything that does not match will be returned instead of everything that does match. (Default is 0)

Return Value

Success - Returns 1.

Failure - Returns 0.

Remarks

This also includes Hash values with the array values.

Example

Return everything that matches

$array = array(0 => 'blue', 1 => 'red', 2 => 'green', 3 => 'red', 4 => 10);
 
$key = Search($array, 'green');
println("Search for 'green' below");
foreach($key as $k <=> $v)
{
	println("Key '$k' Value '$v'");
}
println("Search for 'green' above");
 
println("");
$key = Search($array, 'red');
println("Search for 'red' below");
foreach($key as $k <=> $v)
{
	println("Key '$k' Value '$v'");
}
println("Search for 'red' above");
 
println("");
$key = Search($array, '10', 1);
println("Search for '10' below");
foreach($key as $k <=> $v)
{
	println("Key '$k' Value '$v'");
}
println("Search for '10' above");
 
println("");
$key = Search($array, 10, 1);
println("Search for 10 below");
foreach($key as $k <=> $v)
{
	println("Key '$k' Value '$v'");
}
println("Search for 10 above");
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox