tiptap-php icon indicating copy to clipboard operation
tiptap-php copied to clipboard

Fix multidimensional array check

Open godismyjudge95 opened this issue 2 years ago • 2 comments

This fixes https://github.com/ueberdosis/tiptap-php/issues/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 avatar Oct 01 '23 03:10 godismyjudge95

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

godismyjudge95 avatar Oct 01 '23 04:10 godismyjudge95

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

godismyjudge95 avatar Jan 19 '24 20:01 godismyjudge95