Tiny Config Function in Dot Notation

This is a tiny PHP function to read an array configuration file, and return the key in a dot notation.

Tiny Config Function in Dot Notation

This is a tiny PHP function to read an array configiration file, and return the key in a dot notation

function config($key, $default = null) {
    static $config = null;
    *// Is already read? No=>Read config*
    *if* ($config == null) {
       $config = *include* __DIR__ . '/config.php';
    }
    $temp = $config;
    $path = explode(".", $key);
    *foreach* ($path as $key) {
       *if* (isset($temp[$key])) {
           $temp = $temp[$key];
*           continue*;
       }
        *return* $default;
     }
     *return* $temp;
}

Example:

config("app.name","Default name");

← Previous
MySQL. Script to Convert Old Dates to New
Next →
Interesting "Rules of Management"

Keep Reading

Explore more articles and insights

uid: SafeShortID and HexShortID — Time-Ordered IDs Without the Rude Words

uid: SafeShortID and HexShortID — Time-Ordered IDs Without the Rude Words

Read Article
Bootlegance: 70 Free Bootstrap 5 Themes with Native Dark Mode

Bootlegance: 70 Free Bootstrap 5 Themes with Native Dark Mode

Read Article
A Big, Opinionated List of PHP Libraries (2026 Edition)

A Big, Opinionated List of PHP Libraries (2026 Edition)

Read Article
View All Blog Posts