Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.Start your free trial
Quiz question about array_keys
One of the questions is : "What does the optional argument(s) for array_keys do for us?"
Looking at the PHP docs I understood
$search_value argument contains value that we lookup within values (not keys), and this function returns corresponding keys (array of).
So which answer is right:
A Allows you to search for a value in the keys and provide the option to make your search identical or just equal in match
B Allows you to search for a value in the values and provide the option to make your search identical or just equal in match
I suppose it's an error marking B as wrong answer.
I think A is the answer. The
array_keys() function returns the keys from an array. You can optionally get a subset of the keys by adding arguments. The optional strict would force the key to be identical to the other optional argument. Since it returns values for the key and not values for the values, the answer is A.
See this section of the PHP manual.
As I understand it, the array_keys function returns a numerically-indexed array of the keys from the array you are searching. The value argument allows you to specify a value and return only the keys which have that matching value. In addition, the strict argument would force the value to be of the same data type, as well. So, B is the correct answer.
I just took the quiz and the correct answer is the one I thought. Boris, your answer confirms my explanation. The returned array gives the key value of the locations of blue. In your example, blue appears in spots 0, 3, and 4 of $array. So array_keys() looked for the key word 'blue' and returned the key values where it occurs in the array.