-4

Hello i have an array which looks like this

[0] => Array
        (
            [0] => Array
                (

                    [title] => Alloys
                    [description] => 
                    [content_text] => 
                    [submenu_content_text] => 
                )

            [1] => Array
                (

                    [title] => Anaesthetics
                    [description] => 
                    [content_text] => 
                    [submenu_content_text] => 
                )

        [2]=>()

I want to sort values by title in alphabet order

Does anybody tell me how to do this

Thansk

user3706032
  • 21
  • 2
  • 5

1 Answers1

0

try it.

function msort($array, $key, $sort_flags = SORT_REGULAR) {
    if (is_array($array) && count($array) > 0) {
        if (!empty($key)) {
            $mapping = array();
            foreach ($array as $k => $v) {
                $sort_key = '';
                if (!is_array($key)) {
                    $sort_key = $v[$key];
                } else {
                    foreach ($key as $key_key) {
                        $sort_key .= $v[$key_key];
                    }
                    $sort_flags = SORT_STRING;
                }
                $mapping[$k] = $sort_key;
            }
            asort($mapping, $sort_flags);
            $sorted = array();
            foreach ($mapping as $k => $v) {
                $sorted[] = $array[$k];
            }
            return $sorted;
        }
    }
    return $array;
}

$sortedArray = msort($yourArray, array('title'));
kaantunc
  • 11
  • 2
  • 1
    You are overcomplicating simple thing. You could just use [`usort`](http://www.php.net//manual/en/function.usort.php) – Leri Jun 12 '14 at 11:58