travis / ex
A PHP function to safely extract information from a multi-dimensional object or array.
Installs: 4 449
Dependents: 2
Suggesters: 0
Security: 0
Stars: 2
Watchers: 3
Forks: 1
Open Issues: 0
Requires
- php: >=5.3.0
This package is not auto-updated.
Last update: 2024-12-17 09:39:55 UTC
README
A PHP function to safely extract information from a multi-dimensional object or array.
Install
Normall install via Composer.
Usage
$array = array( 'foo' => array( 'bar' => array( 'foo' => array( 'bar' => 'asdf' ) ) ) ); $value = ex($array, 'foo.bar.foo.bar'); // returns "asdf" $value = ex($array, 'foo.bar.foo.invalid_key'); // returns null $value = ex($array, 'foo.bar.foo.invalid_key', 'default'); // returns "default"
Updates
I added another helper function to safely count arrays:
$array = null; $count = excount($array); // returns 0 instead of error
I wanted this to fix a change in PHP 7.4 which breaks sizeof()
.