[11.x] Add optional ability to array wrap associative arrays #52473
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
These additions allow array wrapping for associative arrays. Currently,
Arr::wrap()
does not wrap an associative array, but simply returns that same array. This feature is fully backwards compatible because the wrapping of associative arrays is opt in.. by passingtrue
toArr::wrap
as the$wrapIfAssoc
argument. This defaults tofalse
which maintains current wrapping behavior.Use Case
Functions that define an array parameter could be passed a list or an associative array. Also, many users implement functions that could be used on 1 data set or many data sets.. i.e. associative arrays. Being able to wrap associative arrays produces slightly more concise code and convenience.
Here,
$params
could either be['id' => 1]
or[['id' => 1], ['id' => 2]]
...Before
After