slice

Extract a part of a String, Number, or Array.


Syntax


Parameters

  • Mixed subject - The entity to slice.
    • String - The portion of the String specified by the start and length parameters will be returned.
    • Number - The Number will be treated as a String.
    • Array - The sequence of items in the Array specified by the start and length parameters will be returned.
  • Number start - The position to start slicing from. If start is non-negative, the position will be calculated from the beginning of subject, otherwise it will be calculated from the end.
  • Number length - The number of elements (characters in a String, or items in an Array) to return. If omitted, everything from start to the end of subject will be returned. If positive, the sequence will contain that many elements, otherwise if negative, the sequence will stop that many elements from the end of subject.
  • Boolean preserve - The optional preserve parameter only has any effect if subject is an Array.
    • false (default) - The keys in the Array returned will be re-assigned from 0.
    • true - The original keys will be retained.


Result

  • Mixed - The resulting sequence.
    • String - If subject is a String or Number.
    • Array - If subject is an Array.

Returns a sequence from subject, defined by start and length.

ptpscript/functions/slice.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