I like to do things without foreach or for loops if possible, out of purely personal preference.
Here's my go for this:
$array_test = array (
0 => array("id_img" => 18, "desciption" => "Super image", "author" => "Person 1"),
1 => array("id_img" => 17, "desciption" => "Another image", "author" => "Person 2"),
2 => array("id_img" => 22, "desciption" => "The last image", "author" => "John Doe"),
);
$result = array_filter( $array_test, function( $value )
{
return $value['id_img'] == 17 ? true : false;
});
$key = array_keys( $result )[0];
print_r( $key );
Instead of loops, I use array_filter() to get only those items in the array that match my rule ( as defined in the Closure's return statement ). Since I know I only have one ID with value of 17 I know I will end up with only one item in the $result array. Then I retrieve the first element from the array keys ( using array_keys( $result )[0] ) - That's the key which holds the id_img = 17 in the original array.