What is the while loop used for in PHP?
- Repeating a block of code as long as a condition is true
- Performing a specific action for each element in an array
- Executing a block of code a certain number of times
- Executing a block of code at least once, then repeating as long as a condition is true
The while loop in PHP is used for repeating a block of code as long as a certain condition is true. It allows you to specify a condition, and the code block will be executed repeatedly until the condition becomes false. The while loop is suitable when you want to repeat a block of code based on a specific condition, and the condition is tested before each iteration. If the condition is initially false, the code block will not be executed at all. Learn more: https://www.php.net/manual/en/control-structures.while.php
Loading...
Related Quiz
- What is the difference between abstract classes and interfaces in PHP? When would you use each?
- You need to sort an associative array in your PHP script based on its keys, in descending order. How would you do this?
- The $_FILES superglobal array in PHP holds information about uploaded files.
- In a PHP do...while loop, the condition is tested ______ the code block is executed.
- Which of the following are valid ways to add comments to PHP code?