You are viewing an older version of the site. Click here to view
the latest version of this page. (This may be a dead link, if so, try the root page of the docs
here.)
== array_contains ==
Copy Code
The output would be:
Copy Code
The output would be:
Copy Code
The output would be:
Copy Code
The output would be:
Copy Code
The output would be:
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 existence of a particular key, use array_index_exists().
=== Vital Info ===
{| style="width: 40%;" cellspacing="1" cellpadding="1" border="1" class="wikitable"
|-
! scope="col" width="20%" |
! scope="col" width="80%" |
|-
! scope="row" | Name
| array_contains
|-
! scope="row" | Returns
| boolean
|-
! scope="row" | Usages
| array, testValue
|-
! scope="row" | Throws
| [[../objects/ms.lang.CastException|ms.lang.CastException]]
|-
! scope="row" | Since
| 3.0.1
|-
! scope="row" | Restricted
| No
|-
! scope="row" | Optimizations
| [[../../Optimizer#NO_SIDE_EFFECTS|NO_SIDE_EFFECTS]]
|}
=== Usages ===
array_contains(array, testValue)=== Examples === ====Example 1==== Demonstrates finding a value Given the following code:
array_contains(array(0, 1, 2), 2)

1 {{function|array_contains}}({{function|array}}(0, 1, 2), 2)
:true====Example 2==== Demonstrates not finding a value Given the following code:
array_contains(array(0, 1, 2), 5)

1 {{function|array_contains}}({{function|array}}(0, 1, 2), 5)
:false====Example 3==== Demonstrates finding a value listed multiple times Given the following code:
array_contains(array(1, 1, 1), 1)

1 {{function|array_contains}}({{function|array}}(1, 1, 1), 1)
:true====Example 4==== Demonstrates finding a string Given the following code:
array_contains(array('a', 'b', 'c'), 'b')

1 {{function|array_contains}}({{function|array}}('a', 'b', 'c'), 'b')
:true====Example 5==== Demonstrates finding a value in an associative array Given the following code:
array_contains(array('a': 1, 'b': 2), 2)

1 {{function|array_contains}}({{function|array}}('a': 1, 'b': 2), 2)
:true===See Also===
[[API/functions/array_index_exists.html|array_index_exists]]
, [[API/functions/array_scontains.html|array_scontains]]
Find a bug in this page? Edit this page yourself, then submit a pull request. (Note this page is automatically generated from the documentation in the source code.)