You are here: Re: Sorting Multidimensional Array? « PHP Language « IT news, forums, messages
Re: Sorting Multidimensional Array?

Posted by Gleep on 01/29/07 22:20

On Mon, 29 Jan 2007 15:25:45 -0000, "benb" <benb@nospam.postalias> wrote:

>Hi
>I've performed a query on Active Directory to pull usernames & mobile
>numbers, using:
>
><snip>
>$read = ldap_search($connect, $base_dn, $filter, $inforequired)
>$info = ldap_get_entries($connect, $read);
>
>This has returned an array (not sure of the type, is it multidimensional, or
>an array of arrays?) with 2 values:
>
>$info[$i]["displayname"][0]
>and
>$info[$i]["mobile"][0]
>
>When I print this information in a table I get the following
>
>John Doe 077654321
>Joe Blogs 071234567
>Alan Smith 077711223
>...etc
>
>How do I go about sorting this array, so that [displayname] is alphabetical?
>I've tried using sort($info) but this seems to wipe the array, I've also
>tried sort($info[0]["displayname"]) but that doesn't seem to sort anything!
>
>Any help, or suggestions much appreciated!
>
>Ben
>




I wanted to copy a few pages from Sams Web development 3rd edition
but motherfuckin adobe reader won't let me copy it.

I've used this technique in some applications i have. You can sort a multidimentionsl array with
this function.

function compare($x, $y)
{
if ($x[1] == $y[1])
return 0;
else if ($x[1] < $y[1])
return -1;
else
return 1;
}

usort ($products, 'compare')

$products would be your multidem array
you can reverse the sort by changing the < to >


if you need more explaination look for book
PHP and MySQL Web Development
Luke Welling / Laura Thomson
This is the book I used to get started with PHP

one of the problems I see is that this will sort on the first name, not the last name
a work around would be to split out the names and recreate another name array
however another problem could surface - what if people use a 3rd name or a hyphen
you have to expect all kind of odd ball scenarios and account for it early in your application.

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация