Consider a scenario where you need to ensure that a particular piece of code only executes once, regardless of how many times a function is called. Which PHP feature or function would you utilize?

  • Singleton Pattern
  • Static Variable
  • sleep()
  • exit()
To ensure a piece of code only executes once, you can use a static variable inside a function to keep track of whether it has already been executed.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *