Got a question that the wiki doesn't answer? Ask on the forum (preferred), or join us on IRC.

BeastNode

CommandHelper/Staged/API/array contains

From EngineHub.org Wiki
Jump to: navigation, search



Vital Info

Name array_contains
Returns boolean
Usages array, testValue
Throws CastException
Since 3.0.1
Restricted
No
Optimizations NO_SIDE_EFFECTS

Description

Checks to see if testValue is in array. For associative arrays, only the values are searched, the keys are ignored. If you need to check for the existance of a particular key, use array_index_exists().

Usages

array_contains(array, testValue)

Examples (How do these work?)

Example 1

Demonstrates finding a value

Given the following code:

1   array_contains(array(0, 1, 2), 2)


The output would be:

:true

Example 2

Demonstrates not finding a value

Given the following code:

1   array_contains(array(0, 1, 2), 5)


The output would be:

:false

Example 3

Demonstrates finding a value listed multiple times

Given the following code:

1   array_contains(array(1, 1, 1), 1)


The output would be:

:true

Example 4

Demonstrates finding a string

Given the following code:

1   array_contains(array('a''b''c'), 'b')


The output would be:

:true

Example 5

Demonstrates finding a value in an associative array

Given the following code:

1   array_contains(array('a': 1, 'b': 2), 2)


The output would be:

:true


See Also

array_index_exists, array_scontains



Navigation menu