ok apologies set -A is for ksh.
Are you doing a while loop for another task or is it purely for this function?
Assuming you want to do other things in your while loop you can try the below code. Otherwise you don't need the while. Saying that you could use while instead of for but below would need changes.
Code:
array=""
array_count=0
for element in $input
do
... do some checking....
array[$array_count]=$element
... do other stuff .....
array_count=$(( $array_count + 1 ))
done