// ou compte tenu de la structure de votre tableau :
$array = array(
'string1' => array('a' => '', 'b' => '', 'c' => ''),
'string2' => array('a' => '', 'b' => '', 'c' => ''),
'string3' => array('a' => '', 'b' => '', 'c' => ''),
);
// you could just
function findIndexOfKey($key_to_index,$array){
return array_search($key_to_index,array_keys($array));
}
// exécuté
print "\r\n//-- Method 1 --//\r\n";
print '#index of: string1 = '.findIndexofKey('string1',$array)."\r\n";
print '#index of: string2 = '.findIndexofKey('string2',$array)."\r\n";
print '#index of: string3 = '.findIndexofKey('string3',$array)."\r\n";
// alternativement
print "\r\n//-- Method 2 --//\r\n";
print '#index of: string1 = '.array_search('string1',array_keys($array))."\r\n";
print '#index of: string2 = '.array_search('string2',array_keys($array))."\r\n";
print '#index of: string3 = '.array_search('string3',array_keys($array))."\r\n";
// récursivement
print "\r\n//-- Method 3 --//\r\n";
foreach(array_keys($array) as $key => $value){
print '#index of: '.$value.' = '.$key."\r\n";
}
// sorties
//-- Method 1 --//
#index of: string1 = 0
#index of: string2 = 1
#index of: string3 = 2
//-- Method 2 --//
#index of: string1 = 0
#index of: string2 = 1
#index of: string3 = 2
//-- Method 3 --//
#index of: string1 = 0
#index of: string2 = 1
#index of: string3 = 2