Filter List Help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Dan1212
Forum Newbie
Posts: 1
Joined: Fri Jul 23, 2010 1:09 pm

Filter List Help

Post by Dan1212 »

Hey, I want to know how I filter a list of emails that I have by provider Example:

List:
admi@gmail.com
admi@ga.com
ffff@gmail.com
xxx@ga.com
sdsd@ga.com
xxxx@gmail.com

I wish it will display it in the order of the provider Example:

xxxx@gmail.com
ffff@gmail.com
admi@gmail.com
sdsd@ga.com
xxx@ga.com
admi@ga.com

I need help writing code to use some functions
User avatar
Jade
Forum Regular
Posts: 908
Joined: Sun Dec 29, 2002 5:40 pm
Location: VA

Re: Filter List Help

Post by Jade »

You'll need to use something like usort and compare the substring from @ to the end of the string. Then in each of those you push all beginning of the domain names. Then you can run a regular sort() on each domain within your array. You'll end up with something like this that you can rebuild the sorted list with:

Code: Select all

Array
(
    [aol] => Array
        (
            [0] => cutiepie8
            [1] => hurley.lost
            [2] => jane.doe
        )
    [ga] => Array
        (
            [0] => apple.paltrow
            [1] => dr.suess
            [2] => spongebob
        )
    [gmail] => Array
        (
            [0] => admi
            [1] => fffff
            [2] => zxyr
        )
)
Post Reply