algorithm: massive level when the user obtains an exp.

I have been working with this throughout the week, it is a leveling system for my application. When a user gets enough exp, it is leveled, everything works fine. But, when a user gets a large amount of exp, he will not get a massive level either. The default value for exp required for each user is 1000. For example:

The user gets 1000 exp, for level 1, it levels up to level 2. It works well that way, but if it gets more than necessary, the flow will not work in the same way. Because the exp is necessary for level 2, it is 1400. Therefore, the algorithm for this if the user gets enough or more than the necessary exp, the current exposure for the next level is multiplied by 1.4.

So going back to that, if the user receives 2,400 EXP, the user should be at level 3, right? But it does not work that way, the user will be at level 2, with the exp (current_exp) of 1,400 with a current experience (necessary level) of 1,400, which is correct, but should be at level 3 with a zero exp. true? so before writing the code below, I'll explain the variables,


$ bet-> amount

It represents the experience gained by the user.

$ curr_exp and $ exp_needed

And the $ curr_exp has a default value of 0 and $ exp_needed has a default value of 1000

Now here's the code, if the user gets an amount equal to or greater than the exp_needed, it increases its level, the current exp_needed will be multiplied by 1.4

if ($ user-> curr_exp> = $ user-> exp_needed) {
$ gainexp = $ bet-> amount;
$ user-> curr_exp = ($ gainexp - $ user-> exp_needed);
$ user-> level = $ user-> level + 1;
$ user-> exp_needed = $ user-> exp_needed * 1.4;
$ user-> save ();

Does it mean that this will need more algorithms behind the code? In which sense is the best for a leveling system? I am new to these systems and leveling algorithms, any help or advice would be much appreciated. Thanks in advance.