Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Array Reader Laravel Package

codeliner/array-reader

Read values from multidimensional PHP arrays using dot-paths with escaping for dotted keys. Typed getters like stringValue() accept defaults when paths are missing, and pathExists() lets you distinguish null values from non-existent paths.

View on GitHub
Deep Wiki
Context7

array-reader

PHP ArrayReader

Build Status

Installation

Installation of codeliner\array-reader uses composer. For composer documentation, please refer to getcomposer.org. Add following requirement to your composer.json

"codeliner/array-reader" : "~2.0"

Usage

You can use the ArrayReader to read single values from a multidimensional array by passing the path to one of the {type}Value() methods. Each {type}Value() method takes a default value as second argument If the path can not be found in the original array, the default is used as return value.

Example

$arrayReader = new ArrayReader(
    array(
        'hash' => array(
            'with' => array(
                'nested' => 'value'
            )
        )
    )
);

echo $arrayReader->stringValue('hash.with.nested'));

//Output: value

$arrayReader = new ArrayReader(
    array(
        'hash' => array(
            'with' => array(
                'nested' => 'value'
            )
        )
    )
);

echo $arrayReader->stringValue('hash.not.existing.path', 'defaultString'));

//Output: defaultString


//If a key in your array contains a dot you escape it in the path with a backslash

$arrayReader = new ArrayReader(
    array(
        'hash' => array(
            'with.dot.key' => array(
                'nested' => 'value'
            )
        )
    )
);

echo $arrayReader->stringValue('hash.with\.dot\.key.nested'));

//Output: value

//If you need to differentiate between a NULL value and a not existing path, you can explicity check if the path exists:

$arrayReader = new ArrayReader(
    array(
        'hash' => array(
            'with' => array(
                'nested' => null
            )
        )
    )
);

if($arrayReader->pathExists('hash.with.nested')) {
    echo "path exists";
}

//Output: path exists
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky
spatie/mailcoach-vapor