The function will do that for you. But this will be very poor smart contract design with high chances of failure.
Let me explain this to you.
What if one of the users have sent you ethers from a smart contract that don't implement the payable function (i.e his smart contract doesn't accept ethers).
Since you are iterating over an array to transfer funds. When you try to refund that malicious user, the transfer call fails:
and this line reverts all the state change and hence the genuine users also don't get their ETH.
Now let's assume you don't have any malicious users but you have around 10K users (or more). The gas for this transaction will exceed block gas limit and eventually, your transaction will always fail.
There is always a solution to every problem.
Always favor pull over push in fund transfers.
This means to allow users to withdraw (pull) their eth instead of pushing eth to their wallet. In this case, only the call of malicious users will fail and won't hamper your genuine users.
Secondly. when users withdraw their eth hence they pay for the gas. Thus there are no chances of exceeding block gas limit.