When I calls this function in other file the function doesn't returns unique value (an incremented value). Also while I echo this function in same file(where the function is made) it works fine.
I know the concept of scope of static variable as I have already tried this by replacing $i by $_SESSION['i'] but no expected result.
Thanks in advance.
But if you are requesting multiple times then the value will be reset on every request and every time the response will be the same. I would suggest to store the value in database or some file. In this case using seesion woludn't be reliable.