0
$string = array('A','B','C','A','B','C');

For example first instance of C in $string would be 2

Is there a simpler way to do this than doing a complex loop in php?

2 Answers 2

3

Use array_search() function. (http://php.net/array_search)

Sign up to request clarification or add additional context in comments.

Comments

1

Array_search() will do exactly what you want.

http://us.php.net/manual/en/function.array-search.php

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.