0
0
PHPprogramming~5 mins

Array search functions in PHP - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the PHP function in_array() do?
It checks if a value exists in an array and returns true if found, otherwise false.
Click to reveal answer
beginner
How does array_search() differ from in_array()?
array_search() returns the key of the found value in the array, or false if not found, while in_array() returns only true or false.
Click to reveal answer
beginner
What is the return value of array_search() if the searched value is not found?
It returns false to indicate the value is not present in the array.
Click to reveal answer
intermediate
Explain the use of the third parameter in in_array() and array_search().
The third parameter is a boolean for strict checking. If true, the functions check both value and type (===). If false or omitted, only value is checked (==).
Click to reveal answer
intermediate
What will array_search('5', [1, 2, 3, 5]) return with strict mode off and on?
With strict mode off (default), it returns the key 3 because '5' loosely equals 5.<br>With strict mode on, it returns false because string '5' is not identical to integer 5.
Click to reveal answer
Which PHP function returns the key of a value in an array?
Aarray_search()
Bin_array()
Carray_key_exists()
Darray_keys()
What does in_array('10', [10, 20, 30]) return by default?
A10
Bfalse
Ctrue
Dnull
If array_search() does not find the value, what does it return?
Afalse
B-1
Cnull
D0
Which parameter controls strict type checking in in_array()?
AFirst parameter
BNo parameter controls this
CSecond parameter
DThird parameter
What will array_search(5, ['5'], true) return?
A0
Bfalse
C1
D5
Describe how to check if a value exists in an array and get its key in PHP.
Think about two functions: one for yes/no, one for key.
You got /5 concepts.
    Explain the difference between loose and strict checking in PHP array search functions.
    Consider how '5' and 5 compare with and without strict mode.
    You got /5 concepts.