How can global variables be used to define include paths in PHP for better code organization?

Global variables can be used to define include paths in PHP for better code organization by setting a global variable to hold the base path of the project. This allows for easy access to include files from various directories without hardcoding the paths in each file. By defining a global variable for the base path, you can ensure consistency and make it easier to update paths in the future.

<?php
// Define a global variable for the base path of the project
define('BASE_PATH', __DIR__);

// Include a file using the global variable for the base path
include BASE_PATH . '/includes/config.php';