Your loop does not exit when there are values in the array which are equal. Add a return 0 clause somewhere to signify when two elements of the array are equal.
That should probably happen when you are out of elements for any of either list (a, b). Because otherwise you will get notices about accessing array-indexes which do not exist. (Your sample gives one such notice)