What will be the output of the following PHP code (3)?

24. What will be the output of the following PHP code?

<?php
function Increment(){
    static $num = 0;
    echo "$num";
    $num++;
}

Increment();
Increment();
Increment();
?>
  1. 000
  2. 111
  3. 011
  4. 012

Answer: D) 012

Explanation:

In the above code, $num is a static variable and it will be initialized once. Thus, the output would be "012".

Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.