I have an array:
$list = array(\'string1\', \'string2\', \'string3\');
I want to get the index for a given value (i.e. 1 for <
The problem is that you don't have a numerical index on your array.
Using array_values() will create a zero indexed array that you can then search using array_search() bypassing the need to use a for loop.
$list = array('string1', 'string2', 'string3');
$index = array_search('string2',array_values($list));