0
0
PHPprogramming~5 mins

Array key and value extraction in PHP - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What function in PHP extracts all the keys from an array?
The array_keys() function extracts all the keys from an array and returns them as a new array.
Click to reveal answer
beginner
How do you get all the values from an array in PHP?
Use the array_values() function to get all the values from an array as a new indexed array.
Click to reveal answer
beginner
Given $arr = ['a' => 1, 'b' => 2];, what does array_keys($arr) return?
It returns ['a', 'b'], which are the keys of the array.
Click to reveal answer
beginner
What will array_values(['x' => 10, 'y' => 20]) return?
It returns [10, 20], the values of the array re-indexed starting from 0.
Click to reveal answer
intermediate
Can array_keys() be used to find keys for a specific value?
Yes, by passing the value as the second argument, array_keys($array, $value) returns all keys that have that value.
Click to reveal answer
Which PHP function returns all keys from an array?
Aarray_keys()
Barray_values()
Carray_search()
Darray_flip()
What does array_values() return?
AAll keys of an array
BThe last value of an array
CAll values of an array
DThe first key of an array
How can you find all keys for a specific value in an array?
Aarray_values($array, $value)
Barray_keys($array, $value)
Carray_search($value, $array)
Darray_flip($array)
What will array_keys(['x' => 5, 'y' => 10]) return?
A['x', 'y']
B[5, 10]
C['5', '10']
D['0', '1']
If you want only the values of an array without keys, which function do you use?
Aarray_keys()
Barray_flip()
Carray_search()
Darray_values()
Explain how to extract keys and values from an array in PHP.
Think about the two main functions for keys and values.
You got /4 concepts.
    How can you find all keys associated with a specific value in a PHP array?
    Use array_keys with a value parameter.
    You got /3 concepts.