There is a saying "Keep your friends close and your enemies closer." No truer saying could be used to describe David's relationship with the Philistines.
The Philistines, on more than one occasion were an enemy to the Hebrews, especially under King Saul. However, they were a friend to David, who even after killing their giant warrior Goliath, years later would give David refuge when Saul was hunting him down to be killed. (1 Samuel 21:10-15; 27:1-28:2; 29:1-11).
Perhaps during those years of "friendship" were when David studied and learned things from the Philistines that he would later use to his advantage when he and the Mighty Men battled them before, during and while he was king.
On the battlefield, one can never be certain your friend one day may become your enemy the next. David certainly could attest to that.
P is for Philistines.