Are there any best practices for handling return values and customizing feedback when using system() in PHP scripts?

When using the system() function in PHP scripts, it is important to handle the return values properly and customize feedback for better error handling. One way to achieve this is by using the return_var parameter of the system() function to capture the return value of the command executed. You can then use this return value to determine if the command executed successfully or encountered an error, and provide appropriate feedback to the user.

// Execute a command using system() and capture the return value
$return_var = 0;
$output = system('ls', $return_var);

// Check the return value to determine success or failure
if ($return_var === 0) {
    echo "Command executed successfully: $output";
} else {
    echo "Error executing command: $output";
}