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
New on Educative
Learn to Code
Learn any Language as a beginner
Develop a human edge in an AI powered world and learn to code with AI from our beginner friendly catalog
🏆 Leaderboard
Daily Coding Challenge
Solve a new coding challenge every day and climb the leaderboard

Free Resources