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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

godismyjudge95
Copy link

@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
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
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
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
1 participant