Core Function Search

From Sputnik Wiki
Revision as of 11:18, 28 April 2012 by UberFoX (Talk | contribs)
Jump to: navigation, search
Search( <array>, <value>, <flag> )

Contents

Description

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

Parameters

array

The array to use.

value

A value to search for.

flag

Optional; If the third parameter strict is set to TRUE then the Search() function will search for identical elements in the array.

This means it will also check the types of the values in the array, and objects must be the same type as well.

Return Value

Success - Returns new array with information.

Failure - Returns empty array.

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