If someone casts "Phantasmal Force" (2nd level illusion) on a foe, in a campaign that uses the optional flanking rules, and it renders to the foe as another attacking creature from a flanking position, could the caster then gain advantage on attack rolls? Could a Rogue use his sneak attack for the imagined creature being within 5 feet of the target?
This is a very tricky question; but a very good one. The primary deciding factor is not rules, be they written or interpreted, but the Dungeon Master's ruling in question.
Since Phantasmal Force creates an illusion so vividly rooted into the afflicted target's mind that the target's thought process rationalizes any interactions with the illusion (an illusion ONLY the afflicted creature can see) to be perceived as real, and an illusion made to look like a creature can deal damage in the form of 'an attack' against the afflicted target, I would rule that yes; Phantasmal Force creates such a realistic illusion as to create opportunities for the 5E Advantage system (granting the rogue sneak attack as below).
"...you can deal an extra 1d6 damage to one creature you hit if you have advantage on the attack roll..."
Keep in mind that I am saying the illusion would grant Advantage (one of the factors a rogue needs to use sneak attack) , not that it counts as an ally creature within 5ft of the target (see below); because the creature is an illusion only perceived by the target and is not physically there for all other intents and purposes.
"...you don't need Advantage on the attack roll if another enemy of the target is within 5ft of it..."
This same reasoning can be said about flanking. If flanking states that the enemy in question must have a physical threat on opposite sides of it, I would render the target not flanked, but certainly distracted or concerned enough with its illusory threat to be unable to put up a proper defense against a REAL enemy coming up behind (or beside) it.
Other Dungeon Master's might interpret this differently and disagree with me. So in this case, point out the entire Phantasmal Force entry to your DM and let he or she make a ruling.