what’s different between _x() and _()

_x() let’s you add a context to your strings. This is useful when you are using the same string in different places. This string may need different translations depending on the language.

Your example would be :

echo 'a1 in context 1 ' . _x('a1', 'context1', 'mydomain');
echo 'a1 in context 2 ' . _x('a1', 'context2', 'mydomain');

There are more examples in this article.