0

This question will probably be easy but I'm having an issue sorting a multi-dimensional array.

I have pulled all the users in a specific OU from ldap and stored them in an array called $info:

$filter = "(objectClass=user)";
$justthese = array(
        "whenCreated",
        "cn",
        "title",
        "userAccountControl",
        "accountExpires",
        "sAMAccountName"
);

$sr = ldap_search($ldap_conn, $basedn, $filter, $justthese);

$info = ldap_get_entries($ldap_conn, $sr);

So then I do a foreach on $info and display the users in a table and stuff.

I want to know, once I have $info, how would I sort this array via the "whenCreated" attribute of each entry?

So, for example, I might have:

Info[0] =

array{

"whenCreated" = 03122015,
"cn" = John Smith
etc

}

and

Info[1] =

array{

"whenCreated" = 01122015,
"cn" = Jane Smith
etc.

}

So, on sorting the array, I'd want $info[1] to precede info[0] because the whencreated attribute in that array is first.

Thanks

EDIT: Re-opening as answer was simple and not covered in that thread.

joshnik
  • 243
  • 1
  • 4
  • 15
  • This is definitely a duplicate. Search for "sort multi dimensional array by column php" –  Dec 03 '15 at 13:22
  • Yeah, you're right Terminus, I imagine that thread will point me in the right direction. Will close the thread - thanks for the link. – joshnik Dec 03 '15 at 13:39
  • 1
    Apologies - answer was far simpler than any of that. I wasn't aware of the ldap_sort() function which will sort search results before you stick them in an array: http://php.net/manual/en/function.ldap-sort.php – joshnik Dec 03 '15 at 13:44
  • good find. Thanks for posting it here for others –  Dec 03 '15 at 13:49

0 Answers0