In what scenarios would using JSON be a better option than using INI format for storing configuration data in PHP?

JSON would be a better option than using INI format for storing configuration data in PHP when you need to store more complex data structures such as nested arrays or objects. JSON is more flexible and can handle a wider range of data types compared to INI format. Additionally, JSON is widely supported in various programming languages and is easy to work with.

// Example of using JSON for storing configuration data
$config = [
    'database' => [
        'host' => 'localhost',
        'username' => 'root',
        'password' => 'password123',
        'database' => 'my_database'
    ],
    'debug' => true
];

$json_config = json_encode($config);
file_put_contents('config.json', $json_config);

// To read the configuration data
$config_data = json_decode(file_get_contents('config.json'), true);