Reorganize and test search of reversed array in matrix for PHP