PHP declare Keyword

PHP default Keyword
PHP continue Keyword

In this article, you will learn how to use declare keyword in PHP. The declare keyword in PHP sets an execution directive for a block of code. If the declare statement is not followed by a block then the directive applies to the rest of the code in the file.

examples of the DECLARE keyword

Example 1. In this example, we run a function after each instruction.

<?php
$count = 0;
function example() {
  global $count;
  $count++;
  echo "$count instructions executed<br>";
}

register_tick_function('example');

declare(ticks=1) {
  $cars = ["Ford", "Volvo", "BMW"];
  foreach($cars as $car) {
    echo "$car <br>";
  }
}
?>
PHP default Keyword
PHP continue Keyword
en English
X
Scroll to Top