Sorting Language Code

Sorting Language Code

To sort Language Code Alphabetically.

Sort Values And to get main language wise and Ksort to sort using key value and also preserve the key value.

Use the Following Code

<?php
$language_list = array();
$language_list['jp-en']='jp-en';
$language_list['tw-en']='tw-en';
$language_list['au-en']='au-en';
$language_list['it-we']='it-we';
$language_list['se-hj']='se-hj';
$language_list['ae-hj']='ae-hj';
$language_list['pu-we']='pu-we';
$language_list['yu-we']='yu-we';
$language_list['se-en']='se-en';
$lang = array();
//print_r("Before Sorting:");
//var_dump($language_list);
    foreach($language_list as $value=>$key) {
        $lang_manuplate[$value] = explode('-', $value);
    }
    $lang_sort = array();
    foreach ($lang_manuplate as $key => $value) {
        $lang_sort[$value[1]][]=$value[0];
    }
    $lang_sort_1 = array();
    foreach ($lang_sort as $key => $value) {
        sort($value);
        $lang_sort_1[$key] = $value;
    }
    ksort($lang_sort_1);
    foreach ($lang_sort_1 as $key => $value) {
        foreach ($value as  $value) {
            $lang[$key][$value.'-'.$key] = $value.'-'.$key;
        }

    }
//print_r("After Sorting:");
//var_dump($lang);

Add new comment

Restricted HTML

  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.
  • Lazy-loading is enabled for both <img> and <iframe> tags. If you want certain elements skip lazy-loading, add no-b-lazy class name.
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.