You want to write a PHP script that outputs 'Ready' only after the entire PHP code finishes running. Which approach ensures this behavior?
hard📝 Application Q8 of 15
PHP - Request Lifecycle
You want to write a PHP script that outputs 'Ready' only after the entire PHP code finishes running. Which approach ensures this behavior?
AUse multiple PHP blocks with echo 'Ready'; in the first block.
BPlace echo 'Ready'; after all PHP code inside the last PHP block before closing.
CWrite echo 'Ready'; outside any PHP tags in plain HTML.
DPut echo 'Ready'; before the opening PHP tag.
Step-by-Step Solution
Solution:
Step 1: Understand PHP execution order
PHP executes code inside PHP tags in order. To output after all code, echo must be last inside PHP.
Step 2: Evaluate options
Place echo 'Ready'; after all PHP code inside the last PHP block before closing. places echo 'Ready'; at the end of PHP code, ensuring it runs last and outputs correctly.
Final Answer:
Place echo 'Ready'; after all PHP code inside the last PHP block before closing. -> Option B
Quick Check:
Last echo inside PHP block outputs final text [OK]
Quick Trick:Echo last inside PHP block to output final text [OK]