xakepehok / array-wildcard-explainer
List all array keys that match wildcard path
0.1.1
2024-05-20 14:00 UTC
Requires
- php: >=7.4.0
- ext-json: *
Requires (Dev)
- phpunit/phpunit: ^9.0
This package is auto-updated.
Last update: 2025-02-20 15:44:18 UTC
README
This helper takes any complicated array and dot-styled wildcard path for passed array, and return new array with all keys, that match passed wildcard path. See examples below.
Installation:
composer require xakepehok/array-wildcard-explainer
Usage
<?php use \XAKEPEHOK\ArrayWildcardExplainer\ArrayWildcardExplainer; $array = [ 'direct' => 1, 'nested' => [ 'value_1' => 11, 'value_2' => 22, 'value_3' => [ ['value' => 111], ['value' => 222], ], ] ]; print_r(ArrayWildcardExplainer::explainOne($array, 'direct')) /* will print * [ * 'direct' * ] */ print_r(ArrayWildcardExplainer::explainOne($array, 'nested.*')) /* will print * [ * 'nested.value_1', * 'nested.value_2', * 'nested.value_3', * ] */ print_r(ArrayWildcardExplainer::explainOne($array, 'nested.value_3')) /* will print * [ * 'nested.value_3' * ] */ print_r(ArrayWildcardExplainer::explainOne($array, 'nested.*.*.value')) /* will print * [ * 'nested.value_3.0.value', * 'nested.value_3.1.value' * ] */