In this article, you will learn about namespace keyword in PHP. The namespace keyword in PHP is used to declare in which namespace a PHP file is operating. Namespaces prevent conflicts between classes that have the same name and can be used to organize code by grouping related classes together.
examples of the NAMESPACE function
Example 1. In this example, we create a Table class in the Html namespace.
<?php
namespace Html;
class Table {
public $title = "";
public $numRows = 0;
public function message() {
echo "<p>Table '{$this->title}' has {$this->numRows} rows.</p>";
}
}
$table = new Table();
$table->title = "My table";
$table->numRows = 5;
?>
<!DOCTYPE html>
<html>
<body>
<?php
$table->message();
?>
</body>
</html>