I have function in PHP, which should bind in MySQL IN statement so many variables, that is in array. My problem is that variable and key is changing but function bind only last
The problem is that BindParam Passes the second value by reference. PHP reuses (or appears to in this case) the address of the $param, and not the actual value. Your foreach could have used:
$stmt->bindParam($key, $data_array[$key]);
This has the effect of binding the address location of the array at that key location, so when your sql executes, it gets the right value.
You probably wanted:
$stmt->bindValue($key, $param);
which should evaluate in the foreach loop instead of at the execute statement, and is a passed value instead of an address location.