I've made 2 examples because you're sort of describing 2 different things. I know English isn't your first language so no problem.
In your description you are finding the first position with a value of 0. Don't forget Arrays are "0" based so the 1st element in an array is "0" not "1".
So in your example 1,2,1,3,5,0,0,0 the first value of "0" would be "5".
[attachment=1:2cke3x09][/attachment:2cke3x09]
If you did want to find the last/highest element of "0" in the array so 1,2,1,3,5,0,0,0 it would be "7".
[attachment=0:2cke3x09][/attachment:2cke3x09]