How to create an element query in PHP with custom field names in variables?
You can use the Craft::configure() for that.. imagine your array looks like

$criteria = [
    'age' =&gt; ['and', '&gt;=30', '&lt;=50'],
    'enabled' =&gt; false
    'status' =&gt; null,
]


You can do

$query = User::find();
Craft::configure($query, $criteria);

$users = $query-&gt;all();


Or you can just use the parameter based syntax instead of the functional one 

$users-&gt;$key = $value;


You'll receive a deprecated error when you don't fetch your users. Your so called $users variable hast actually nothing to do with users it's a really bad name because one might think users store information about a list of users but that's not the case. $users is a Query that looks for elements with the type craft\elements\user in your database. You'll receive your list of users when you execute your Query with one(), all() or something like that.