John Gerstner has an excellent explanation of this issue; the various meanings of "foreknowledge" in his address given at the PCRT Conference 1978 which I attended. The transcript can be found here: TULIP
And, here is the relevant section:
Fasten your seat belts for a moment, and brace yourselves for what is going to sound like absolute, unmitigated dogmatism. What that word, foreknew means is: whom He fore loved; whom He fore owned; whom He fore chose as His own. That doesn’t sound like foreknowledge does it? Not in the ordinary use of the English language. But you see unfortunately, you see we don’t have two words in the English language to distinguish mere information about, and actual communion with. We use one word for two ideas. And unfortunately here, clearly the idea is not, not in the sense to have information about, but actually love for and communion with. And all I have to do is remind you, as my wife reminded me I didn’t remind them in Pittsburgh last week, is that the Bible uses language that way all the time. The Lord knows the way of the righteous, but the way of the wicked shall perish. Now doesn’t the Lord know the way of the wicked, as well as, the way of the righteous, as far as having perfect information is concerned. When that says the Lord knows the way of the righteous, in a way that He doesn’t know the way of the wicked, this isn’t talking about not having information about, but not having love for. When Christ slams that door in the foolish virgins face, who refuses to admit that after that unfortunate pleading, far from me I never knew you, of course He didn’t intimate that for a moment He isn’t acquainted with them—He never owned them as His.
At the last judgment, you shall say, so haven’t I prophesied in they name; haven’t I cast out devils in thy name; haven’t I done mighty works in thy name? Depart from me ye workers of iniquity, I never knew you. He knows them so well, He designates them as workers of iniquity when He says I never knew you. You see my friends what that golden chain means is, whom God for loved, He predestinated to a very special benefit, here spelled out as: calling; justification; and glorification. And so it comes to pass that God having foreknown, fore loved, foreordained, unconditionally elected, certain persons that the purpose of the atonement comes into sharp focus.