conditional statement for foreach