Open In App

PHP filegroup() Function

Last Updated : 24 Apr, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

The filegroup() is an inbuilt function in PHP that returns the filegroup. This function returns a group id that can resolve using posix_getgrigid() to a name.

Syntax:

filegroup(string $filename): int|false

Parameter: This function has only one parameter.

  • filename: A name of the file or path of the file

Return value: This function returns the numerical group id if the function is successful otherwise the function will return "false". Group id can resolve using the posix_getgrgid() function.

Example 1: The following code demonstrates the filegroup() function.

PHP
<?php

$file = 'text.txt';
$group_id = filegroup($file);

// ID of the group we want to check for
$expected_group_id = 1000; 

if ($group_id === $expected_group_id) {
    echo "The file $file is owned by the expected group.";
} else {
    echo "The file $file is not owned by the expected group.";
}

?>

Output:

The file text.txt is owned by the expected group.  

Example 2: In this program, we will print the group id of the file.

PHP
<?php

$fileName = 'text.txt' ;

print_r(filegroup($fileName));

?>

Note: Output will be different according to your system.

Output:

1000

Reference: https://www.php.net/manual/en/function.filegroup.php


Next Article

Similar Reads