So there is a friendship_request table:
+--------+----------+
| sender | receiver |
+--------+----------+
| 1 | 2 |
| 2 | 1 |
+--------+----------+
Two users are friends if both have sent each other a request.
I'm using PHP's array_intersect with arrays containing all the friends of each user to determine if they are connected through friends of friends.
i.e.
1 <--> 2 <--> 3
What is the most efficient way to find if two users have friends that have friends that are friends with each other. i.e.
+--------+----------+
| sender | receiver |
+--------+----------+
| 1 | 2 |
| 2 | 1 |
| 2 | 3 |
| 3 | 2 |
| 3 | 4 |
| 4 | 3 |
+--------+----------+
1 <--> 2 <--> 3 <--> 4
User 1 should know of his relationship with User 4.
PS: It's ok with PHP/pseudocode or MySQL
Edit: I do not want to create another table or views. I want to get the best solution using the resources described above.