Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 4 additions & 13 deletions src/ArrayHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,6 @@ public static function applyModifiers(array $data): array
* $fullName = \Yiisoft\Arrays\ArrayHelper::getValue($user, function ($user, $defaultValue) {
* return $user->firstName . ' ' . $user->lastName;
* });
* // using dot format to retrieve the property of embedded object
* $street = \Yiisoft\Arrays\ArrayHelper::getValue($users, 'address.street');
* // using an array of keys to retrieve the value
* $value = \Yiisoft\Arrays\ArrayHelper::getValue($versions, ['1.0', 'date']);
* ```
Expand Down Expand Up @@ -323,7 +321,7 @@ private static function getRootValue($array, $key, $default)
* Retrieves the value of an array element or object property with the given key or property name.
* If the key does not exist in the array or object, the default value will be returned instead.
*
* The key may be specified in a dot format to retrieve the value of a sub-array or the property
* The key may be specified in a dot-separated format to retrieve the value of a sub-array or the property
* of an embedded object. In particular, if the key is `x.y.z`, then the returned value would
* be `$array['x']['y']['z']` or `$array->x->y->z` (if `$array` is an object). If `$array['x']`
* or `$array->x` is neither an array nor an object, the default value will be returned.
Expand All @@ -334,15 +332,7 @@ private static function getRootValue($array, $key, $default)
* Below are some usage examples,
*
* ```php
* // working with array
* $username = \Yiisoft\Arrays\ArrayHelper::getValue($_POST, 'username');
* // working with object
* $username = \Yiisoft\Arrays\ArrayHelper::getValue($user, 'username');
* // working with anonymous function
* $fullName = \Yiisoft\Arrays\ArrayHelper::getValue($user, function ($user, $defaultValue) {
* return $user->firstName . ' ' . $user->lastName;
* });
* // using dot format to retrieve the property of embedded object
* // using separated format to retrieve the property of embedded object
* $street = \Yiisoft\Arrays\ArrayHelper::getValue($users, 'address.street');
* // using an array of keys to retrieve the value
* $value = \Yiisoft\Arrays\ArrayHelper::getValue($versions, ['1.0', 'date']);
Expand All @@ -354,7 +344,8 @@ private static function getRootValue($array, $key, $default)
* `function($array, $defaultValue)`.
* @param mixed $default the default value to be returned if the specified array key does not exist. Not used when
* getting value from an object.
* @param string $delimiter
* @param string $delimiter a separator, used to parse string $key for embedded object property retrieving. Defaults
* to "." (dot).
*
* @return mixed the value of the element if found, default value otherwise
*/
Expand Down