======search====== Search a [[PTPScript:Types:String|String]], [[PTPScript:Types:Number|Number]], or [[PTPScript:Types:Array|Array]] for a value. \\ **Syntax** * ''[[PTPScript:Types:Mixed|Mixed]] search( [[PTPScript:Types:Mixed|Mixed]] subject, [[PTPScript:Types:Mixed|Mixed]] search [, [[PTPScript:Types:Boolean|Boolean]] all [, [[PTPScript:Types:Boolean|Boolean]] strict [, [[PTPScript:Types:Boolean|Boolean]] reverse [, [[PTPScript:Types:Number|Number]] start ] ] ] ] )'' \\ **Parameters** * [[PTPScript:Types:Mixed|Mixed]] ''subject'' - The entity to search. * [[PTPScript:Types:String|String]] - The String is searched for any occurrences of ''search''. * [[PTPScript:Types:Number|Number]] - The Number will be treated as a String. * [[PTPScript:Types:Array|Array]] - The Array is searched for any items that match ''search''. * [[PTPScript:Types:Mixed|Mixed]] ''search'' - The values to search for. * [[PTPScript:Types:String|String]] - ''subject'' is searched for any occurrences of the String. * [[PTPScript:Types:Number|Number]] - If ''subject'' is a String, the Number will be treated as a String. Otherwise, matching depends on the ''strict'' parameter. * [[PTPScript:Types:Array|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. * [[PTPScript:Types:Boolean|Boolean]] - This only has any effect if ''subject'' is an Array, in which case, any occurrences will be searched for. * [[PTPScript:Types:Boolean|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. * [[PTPScript:Types:Boolean|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. * [[PTPScript:Types:Boolean|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. * [[PTPScript:Types:Number|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** * [[PTPScript:Types:Mixed|Mixed]] - The matches. * [[PTPScript:Types:Number|Number]] - If ''all'' is **''false''**, and ''subject'' is a String, or the first match is a numeric key if ''subject'' is an Array. * [[PTPScript:Types:String|String]] - If ''all'' is **''false''**, and the first match in an Array ''subject'' has a String key. * [[PTPScript:Types:Array|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. * [[PTPScript:Types:Boolean|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 ''[[PTPScript:Operators:Comparison|in]]'' [[PTPScript:Operators|Operator]] can be used.