Method `[]()
- Method
`[]
mixed`[](objectarg,mixedindex)
mixed`[](objectarg,stringindex)
function(:void) `[](intarg,stringindex)
int`[](stringarg,intindex)
mixed`[](arrayarg,intindex)
mixed`[](arrayarg,mixedindex)
mixed`[](mappingarg,mixedindex)
bool`[](multisetarg,mixedindex)
mixed`[](programarg,stringindex)
mixed`[](objectarg,mixedstart,mixedend)
string`[](stringarg,intstart,intend)
array`[](arrayarg,intstart,intend)- Description
Indexing.
This is the function form of expressions with the
[]operator, i.e.a[i]is the same aspredef::`[](a,i).- Returns
If
argis an object that implements lfun::`[](), that function is called with theindexargument.Otherwise, the action depends on the type of
arg:argcan have any of the following types:objectThe non-protected (i.e. public) symbol named
indexis looked up inarg.intThe bignum function named
indexis looked up inarg. The bignum functions are the same as those in the Gmp.mpz class.stringThe character at index
indexinargis returned as an integer. The first character in the string is at index0and the highest allowed index is thereforesizeof(. A negative index number accesses the string from the end instead, fromarg)-1-1for the last char back to-sizeof(for the first.arg)arrayIf
indexis an int, index numberindexofargis returned. Allowed index number are in the range[-sizeof(; see the string case above for details.arg)..sizeof(arg)-1]If
indexis not an int, an array of all elements inargindexed withindexare returned. I.e. it's the same as doingcolumn(.arg,index)mappingIf
indexexists inargthe corresponding value is returned. OtherwiseUNDEFINEDis returned.multisetIf
indexexists inarg,1is returned. OtherwiseUNDEFINEDis returned.programThe non-protected (i.e. public) constant symbol
indexis looked up inarg.As a compatibility measure, this function also performs range operations if it's called with three arguments. In that case it becomes equivalent to:
`[..] (arg, start, Pike.INDEX_FROM_BEG, end, Pike.INDEX_FROM_BEG)See `[..] for further details.
- Note
An indexing expression in an lvalue context, i.e. where the index is being assigned a new value, uses `[]= instead of this function.
- See also