Skip to content
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

Closed
wants to merge 4 commits into from
Closed

[5.2] Add Arr::unDot() method #13897

wants to merge 4 commits into from

Conversation

mustafaaloko
Copy link
Contributor

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.

@GrahamCampbell GrahamCampbell changed the title Add Arr::unDot() method [5.2] Add Arr::unDot() method Jun 6, 2016
@GrahamCampbell
Copy link
Member

Interesting idea. :)

@lagbox
Copy link
Contributor

lagbox commented Jun 7, 2016

Past attempt #5663

@lucasmichot
Copy link
Contributor

lucasmichot commented Jun 7, 2016

Already rejected in #4292

But I am for this

public static function unDot($array, $recursively = true)
{
$results = [];

Copy link
Contributor

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

Copy link
Member

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?

Copy link
Contributor

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

@mustafaaloko
Copy link
Contributor Author

@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?

@mustafaaloko
Copy link
Contributor Author

mustafaaloko commented Jun 7, 2016

Let's see what happens after two years ;). For me it looks a useful method to have.

@lucasmichot
Copy link
Contributor

@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?

No need to go through a loop for an empty array either ;-)

* @param bool $recursively
* @return array
*/
public static function unDot($array, $recursively = true)
Copy link
Member

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.

@mustafaaloko
Copy link
Contributor Author

@JosephSilber Done. Thank you!

@taylorotwell
Copy link
Member

Holding off on this. Useful as a package if you need it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants