Skip to content
Advertisement

Use php function in php form

I am new in php, I am solving one task.

  • Create a form with 2 text fields to enter only numbers (treat) and will mean number and power.
  • After pressing the button the result is displayed on the same page, and the result is determined by recursive function
  • in case you forget to enter a number, the number 2 will be inserted automatically.

I have this for now, but I don’t know how to proceed. Can you advise me please?

JavaScript

Advertisement

Answer

I think you are missing a key concept here. What is recursion.

A recursive function is a function that calls itself during its execution. https://en.wikipedia.org/wiki/Recursion_(computer_science)

For your question this is an acceptable solution I believe:

JavaScript

Another implementation of the recursive function is

JavaScript

If I am not mistaken the difference in performance is N vs log(N).

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement