New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[5.2] Add Arr::unDot() method #13897
Conversation
Interesting idea. :) |
Past attempt #5663 |
Already rejected in #4292 But I am for this |
public static function unDot($array, $recursively = true) | ||
{ | ||
$results = []; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From here, no need to go on if $array
is empty
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Who cares? What's the cost of doing a foreach
on an empty array?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No cost, just relying on what has been done for has
, get
and forget
@lucasmichot even if empty, is it a problem to go on? cause it will not enter loops and empty $results will be returned, right? Thoughts? |
Let's see what happens after two years ;). For me it looks a useful method to have. |
No need to go through a loop for an empty array either ;-) |
* @param bool $recursively | ||
* @return array | ||
*/ | ||
public static function unDot($array, $recursively = true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of $recursively
, wouldn't it make sense to accept a $depth
? If can default to INF
.
@JosephSilber Done. Thank you! |
Holding off on this. Useful as a package if you need it. |
Expand a dotted-key array. It acts the opposite way of Arr::dot().
Note: I am not sure about the method name itself (is it good or not). If acceptable for merge, then we can change the method name.