Testing - PHP

array_search

Example #1

Note

Depending on how the conditional test is written, array_search may interpret the first element of an array as false because of it's index value of 0.[1][2] Example #4 demonstrates how a simple conditional test fails to produce the expected outcome. Example #7 demonstrates a more robust conditional test that produces the expected outcome.

Cryptocurrencies Array
Array
(
    [0] => AVAX
    [1] => BTC
    [2] => ADA
    [3] => ETH
    [4] => ENS
    [5] => ORDI
    [6] => DOT
    [7] => SOL
    [8] => STX
    [9] => XLM
    [10] => DJT
    [11] => UNI
    [12] => ZIL
)
array_search example #1

Search $array__cryptocurrencies__symbols for STX

8
array_search example #2

STX is in array...

array_search example #3

FOO is NOT in array...

array_search example #4

XLM is in array...

array_search example #5

AVAX is NOT in array...

array_search example #6

AVAX is in array...

array_search example #7

ZIL is in array...