What is getcwd in PHP?

getcwd is a PHP function that returns the current directory in which the program is being run.

Syntax

getcwd(): string|false

Parameters

The function does not take any parameters.

Return value

If successful, the function returns the current working directory. Otherwise, it returns false.

Code

<?php
// prints the current directory
echo getcwd() . "\n";
?>

Expected output

/home/educative

Free Resources