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

Fix multidimensional array check #39

Merged
merged 2 commits into from
Aug 12, 2024
Merged

Conversation

godismyjudge95
Copy link
Contributor

@godismyjudge95 godismyjudge95 commented Oct 1, 2023

This fixes #25

The issue is that the count method of checking if an array is multidimensional does not account for an edge case of a sub empty array:
https://3v4l.org/16rVK

This issue is discussed rather in depth here: https://stackoverflow.com/questions/145337/checking-if-array-is-multidimensional-or-not

Based off the testing done by the solution poster, this method of testing for a multidimensional array is the fastest while producing the correct output:

function is_multi2($a) {
    foreach ($a as $v) {
        if (is_array($v)) return true;
    }
    return false;
}

This PR adds a private method isMultidimensionalArray implementing that method.
I have tested this locally and it works properly, let me know if I need to create a test for it.

@godismyjudge95
Copy link
Contributor Author

I found it was relatively easy to add a failing test for this - so I went ahead and added it to the PR.

@godismyjudge95
Copy link
Contributor Author

Any chance this could get merged in? This is breaking a project of ours @timoisik

marvinosswald added a commit to marvinosswald/tiptap-php that referenced this pull request May 21, 2024
Copy link
Contributor

@nperez0111 nperez0111 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution, sorry for the wait

@nperez0111 nperez0111 merged commit d617b6c into ueberdosis:main Aug 12, 2024
@godismyjudge95 godismyjudge95 deleted the patch-1 branch August 12, 2024 13:18
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.

Array to string conversion
2 participants