tiptap-php
tiptap-php copied to clipboard
Fix multidimensional array check
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.
I found it was relatively easy to add a failing test for this - so I went ahead and added it to the PR.
Any chance this could get merged in? This is breaking a project of ours @timoisik