Core Function Search
From Sputnik Wiki
(Difference between revisions)
(Created page with "<pre> Grep( <array>, <pattern>, <flag> ) </pre> === Description === Returns a new array consisting of the elements of the input array that match the given regex pattern. === P...") |
|||
Line 1: | Line 1: | ||
<pre> | <pre> | ||
− | + | Search( <array>, <value>, <flag> ) | |
</pre> | </pre> | ||
=== Description === | === Description === | ||
− | Returns a new array consisting of the elements of the input array that match the given | + | Returns a new array consisting of the elements of the input array that match the given value. |
=== Parameters === | === Parameters === | ||
Line 13: | Line 13: | ||
The array to use. | The array to use. | ||
− | ==== | + | ==== value ==== |
− | A | + | A value to search for. |
==== flag ==== | ==== flag ==== | ||
− | Optional; If the | + | 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 === | === Return Value === | ||
− | Success - Returns | + | Success - Returns new array with information. |
− | Failure - Returns | + | Failure - Returns empty array. |
=== Remarks === | === Remarks === |
Revision as of 11:18, 28 April 2012
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");