Jump to content
Sign in to follow this  
smus

Array index by its value (key)

Recommended Posts

How to get an array index by its value (key)? Is there a special function for that in PHP?

For example, I have an array $a ["zero","one","two"] and a variable $b = "two", I know the value is in the array, but I don't know its index.

Share this post


Link to post
Share on other sites

You have to iterate through the array and compare each value to $b, when you find a match return the key.

Share this post


Link to post
Share on other sites

Oh, right. PHP has it built in. I was on my phone so I wasn't checking the reference.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...