Can you have people in your world in minecraft or even though they are far away?

I was with my friend at my house she was right next to me and she could come into my world can you play multiplayer in minecraft pe even though they aren't in the same house or place as yoi

In order to play Minecraft with other people who are NOT on the same LAN as you, there's pretty much two options:

1) Set up a "Virtual LAN" -- This is done with LogMeIn's Hamachi software where you & your friend can connect to each other's computers as if they're on the same LAN. This way, when they start up their offline world, they can just hit the "LAN" button & allow others to join in on the same network.

This can be a little complicated (as Hamachi isn't user-friendly & has some major restrictions) & the world is only available while the host is playing.

2) Set up an online Minecraft server -- This is generally the better option as it allows players to enjoy the same world from different computers located practically anywhere in the world. For personal / private servers, you will need to have the server software running on your computer to make the world accessible to others, but you do not have to in the game itself (as the server software is handling the world for you). This can be a little more challenging to initially set up as you have to know your connection speeds & your hardware specs to avoid having the server get overloaded.

You can pay for a private / public server to do the hosting for you, which can make it more enjoyable for all & even Mojang has their own service called "Minecraft Realms" which costs $13 / mo (discount available for multi-month subscriptions) to have your own private server to share with 20 people & have up to 10 people online at one time. Prices & features available with other online server services will greatly vary.

While you may not be thrilled dealing with a monthly subscription, it can definitely eliminate the headaches of running your own server & can be affordable if your friends are willing to pitch in (depending on your friends, could be like $2-$5 / month / person).

Sorry for not going into the exact details on HOW to do these options, as I don't want to overload with stuff you may not want at this time. However, what you're asking CAN be done as it's something that I've done (with BOTH OPTIONS) personally.

Hopes this helps!