Chad
Chad

Reputation: 2455

Getting the first instance of an item in an array

$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?

Upvotes: 0

Views: 2097

Answers (2)

Abinadi
Abinadi

Reputation: 680

Array_search() will do exactly what you want.

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

Upvotes: 1

Cesar
Cesar

Reputation: 3519

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

Upvotes: 3

Related Questions