1

Maybe my brain is just working but I can't figure out how to sort this array according to the Icelandic alphabet. There MUST be a clean way of doing this right? ( I want to sort it by the value of name ) FYI this is the Icelandic alphabet aábdðeéfghiíjklmnoóprstuúvxyýþæö.

$isAlphabet = 'aábdðeéfghiíjklmnoóprstuúvxyýþæö';

$myGang = array();
$asdf22 = new stdClass();
$asdf22->name = 'Þröstur';
$asdf22->email = 'who@cares.is';

$asdf202 = new stdClass();
$asdf202->name = 'Árni';
$asdf202->email = 'who@cares.is';

$asdf52 = new stdClass();
$asdf52->name = 'Arnar';
$asdf52->email = 'who@cares.is';

$asdf55 = new stdClass();
$asdf55->name = 'Óskar';
$asdf55->email = 'who@cares.is';

$asdf33 = new stdClass();
$asdf33->name = 'Aðalheiður';
$asdf33->email = 'who@cares.is';

$asdf13 = new stdClass();
$asdf13->name = 'Baldur';
$asdf13->email = 'who@cares.is';

$myGang[22] = $asdf22;
$myGang[202] = $asdf202;
$myGang[55] = $asdf55;
$myGang[52] = $asdf52;
$myGang[33] = $asdf33;
$myGang[13] = $asdf13;

sort($myGang); // I know this is not the right way..
print_r($myGang);

/* right order: Arnar Aðalheiður Árni Baldur Óskar Þröstur

but this is the output:

Array
(
    [0] => stdClass Object
        (
            [name] => Arnar
            [email] => who@cares.is
        )

    [1] => stdClass Object
        (
            [name] => Aðalheiður
            [email] => who@cares.is
        )

    [2] => stdClass Object
        (
            [name] => Baldur
            [email] => who@cares.is
        )

    [3] => stdClass Object
        (
            [name] => Árni
            [email] => who@cares.is
        )

    [4] => stdClass Object
        (
            [name] => Óskar
            [email] => who@cares.is
        )

    [5] => stdClass Object
        (
            [name] => Þröstur
            [email] => who@cares.is
        )

)
DoctorArnar
  • 160
  • 1
  • 8
  • 2
    am too lazy to write an answer. Leave you with a link: http://sgehrig.wordpress.com/2008/09/24/on-how-to-sort-an-array-of-utf-8-strings/ – Gordon Aug 15 '13 at 18:03

0 Answers0