search

Search a String, Number, or Array for a value.


Syntax


Parameters

  • Mixed subject - The entity to search.
    • String - The String is searched for any occurrences of search.
    • Number - The Number will be treated as a String.
    • Array - The Array is searched for any items that match search.
  • Mixed search - The values to search for.
    • String - subject is searched for any occurrences of the String.
    • Number - If subject is a String, the Number will be treated as a String. Otherwise, matching depends on the strict parameter.
    • Array - This only has any effect if subject is an Array, in which case, any occurrences will be searched for; that is, only sub-Arrays that match search will be found.
    • Boolean - This only has any effect if subject is an Array, in which case, any occurrences will be searched for.
  • Boolean all - Whether to search for all matches, or just the first.
    • false (default) - Just the first match will be found, and its position returned.
    • true - All matches will be found, in which case their positions will be returned as an Array.
  • Boolean strict - Whether to employ strict matching.
    • false (default) - If subject is a String, the match will be case-insensitive. Otherwise, if subject is an Array, item types will not be checked, only item values.
    • true - If subject is a String, the match will be case-sensitive. Otherwise, if subject is an Array, item types will have to match as well as values. Array searches are always case-sensitive.
  • Boolean reverse - Whether to start at the end of subject.
    • false (default) - subject will be searched from start to end.
    • true - subject will be searched from end to start. The first match will therefore be the last match, and if all is true then the Array of matches will be in reverse order.
  • Number start - The optional start parameter only has any effect if subject is a String (or a Number), and is the position to start searching from. If start is non-negative, the position will be calculated from the beginning of subject, otherwise it will be calculated from the end. If reverse is true, this calculation will be reversed, although the positions returned will always be counted from the actual start of subject.


Result

  • Mixed - The matches.
    • Number - If all is false, and subject is a String, or the first match is a numeric key if subject is an Array.
    • String - If all is false, and the first match in an Array subject has a String key.
    • Array - If all is true, all the matches will be returned as an Array. If subject is a String, all the match positions will be numeric, otherwise if subject is an Array, some match positions can be Strings, as the keys of the matches will be returned.
    • Boolean - If no matches are found, false will be returned.

Returns the positions of either the first match or all matches of search in subject.

For quick presence checks, the in Operator can be used.

ptpscript/functions/search.txt · Last modified: 2007/01/24 10:15
 
 
 
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki