Skip to content
PHP Logo

How can PHP be used to output error codes for troubleshooting specific actions, such as directory creation?

To output error codes for troubleshooting specific actions like directory creation in PHP, you can use the `mkdir` function to create the directory and check if it was successful. If the directory creation fails, you can use `error_get_last()` function to retrieve the last error that occurred and output the error code.

php
$dir = 'path/to/directory';

if (!mkdir($dir, 0777, true)) {
    $error = error_get_last();
    echo "Error code: " . $error['type'];
}