Question:Using PHP I can return the key by looking up the value inside an array.
How can I return the key by fetching the value within a given array?
I’ve already tried using its functions: .indexOf() or .findIndex()
another doubt in this case is it better to use Array or Class? Is it possible to return the class key?
Answer:Arrays don’t have keys, only numeric indexes. When you pass a string to an Array, you are actually creating a new property for the Array object, not a new item in the Array data (for example,
.lengthis a property of an Array, not an indexed value).
If you need keys, use an
object, which is structured as follows:
If you have better answer, please add a comment about this, thank you!