2

How to find out that foo is at the position of 2?: array('boo', 'moo', 'foo');

1
  • I hope you were asking of the key, not the "position" Commented Mar 8, 2010 at 5:02

3 Answers 3

10
$key = array_search("foo", $array);
Sign up to request clarification or add additional context in comments.

Comments

4

print_r ( array_search ( 'value',$array_from ) );

Comments

2

If you want to find the keys for all occurences of 'foo' (if you know there will be duplicates) then use:

$result = array_keys( $yourArray, 'foo' );

This will return an array with all corresponding keys. You see, array_search will only return the key of the first occurence. Be aware of this.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.