Method `[]()
- Method `[]
mixed
`[](object
arg
,mixed
index
)
mixed
`[](object
arg
,string
index
)
function
(:void
) `[](int
arg
,string
index
)
int
`[](string
arg
,int
index
)
mixed
`[](array
arg
,int
index
)
mixed
`[](array
arg
,mixed
index
)
mixed
`[](mapping
arg
,mixed
index
)
bool
`[](multiset
arg
,mixed
index
)
mixed
`[](program
arg
,string
index
)
mixed
`[](object
arg
,mixed
start
,mixed
end
)
string
`[](string
arg
,int
start
,int
end
)
array
`[](array
arg
,int
start
,int
end
)- Description
Indexing.
This is the function form of expressions with the
[]
operator, i.e.a[i]
is the same aspredef::`[](a,i)
.- Returns
If
arg
is an object that implements lfun::`[](), that function is called with theindex
argument.Otherwise, the action depends on the type of
arg
:arg
can have any of the following types:object
The non-protected (i.e. public) symbol named
index
is looked up inarg
.int
The bignum function named
index
is looked up inarg
. The bignum functions are the same as those in the Gmp.mpz class.string
The character at index
index
inarg
is returned as an integer. The first character in the string is at index0
and the highest allowed index is thereforesizeof(
. A negative index number accesses the string from the end instead, fromarg
)-1-1
for the last char back to-sizeof(
for the first.arg
)array
If
index
is an int, index numberindex
ofarg
is returned. Allowed index number are in the range[-sizeof(
; see the string case above for details.arg
)..sizeof(arg
)-1]If
index
is not an int, an array of all elements inarg
indexed withindex
are returned. I.e. it's the same as doingcolumn(
.arg
,index
)mapping
If
index
exists inarg
the corresponding value is returned. OtherwiseUNDEFINED
is returned.multiset
If
index
exists inarg
,1
is returned. OtherwiseUNDEFINED
is returned.program
The non-protected (i.e. public) constant symbol
index
is 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