Массив вида массивов MultiDiminsional больше чем на Одном “столбце” (ключ) с указанными опциями вида

Вы можете редактировать соответствующий файл темы *.json. Например, если вы используете тему Dark + (по умолчанию темная) , вы можете найти файл json темы в extensions/theme-defaults/themes/dark_plus.json. В этом файле мы находим следующее правило темы text mate:

{
    "name": "Variable and parameter name",
    "scope": [
        "variable",
        "meta.definition.variable.name",
        "support.variable",
        "entity.name.variable"
    ],
    "settings": {
        "foreground": "#9CDCFE"
    }
}

Обратите внимание, что некоторые темы не определяют стили для переменной области, поэтому вам придется добавить свою собственную (например, приведенный выше фрагмент). Также не все стили именования переменных определены в файле грамматики c ++. Для получения дополнительной информации о том, как добавить вашу конкретную грамматику стиля именования, вы можете увидеть этот ответ .

6
задан JCobb 1 May 2009 в 04:12
поделиться

3 ответа

This should work for the situation you describe.

usort($arrayToSort, "sortCustom");

function sortCustom($a, $b)
{
    $cityComp = strcmp($a['city'],$b['city']);
    if($cityComp == 0)
    {
        //Cities are equal.  Compare zips.
        $zipComp = strcmp($a['zip'],$b['zip']);
        if($zipComp == 0)
        {
            //Zips are equal.  Compare last names.
            return strcmp($a['last_name'],$b['last_name']);
        }
        else
        {
            //Zips are not equal.  Return the difference.
            return $zipComp;
        }
    }
    else
    {
        //Cities are not equal.  Return the difference.
        return $cityComp;
    }
}

You could condense it into one line like so:

function sortCustom($a, $b)
{
    return ($cityComp = strcmp($a['city'],$b['city']) ? $cityComp : ($zipComp = strcmp($a['zip'],$b['zip']) ? $zipComp : strcmp($a['last_name'],$b['last_name'])));
}

As far as having a customizable sort function, you're reinventing the wheel. Take a look at the array_multisort() function.

3
ответ дан 10 December 2019 в 02:53
поделиться

You might want to try using usort. All you have to do is make a functions that tell the sorter how to sort it. The docs have more info on how to do that.

1
ответ дан 10 December 2019 в 02:53
поделиться

В PHP 5.3 каждый параметр в массиве должен быть ссылкой при вызове array_multisort() с call_user_func_array().

Эта функция сортирует многомерный массив и показывает способ построения массива ссылающихся параметров, который работает корректно.

function msort()
{
  $params = func_get_args();
  $array = array_pop($params);

  if (!is_array($array))
    return false;

  $multisort_params = array();
  foreach ($params as $i => $param) 
  {
    if (is_string($param)) 
    {
      ${"param_$i"} = array();
      foreach ($array as $index => $row) 
      {
        ${"param_$i"}[$index] = $row[$param];
      }
    }
    else 
      ${"param_$i"} = $params[$i];

    $multisort_params[] = &${"param_$i"};
  }
  $multisort_params[] = &$array; 

  call_user_func_array("array_multisort", $multisort_params);

  return $array;
}

Пример:

$data - заданный массив из вопроса

$sorted_data = msort('city', SORT_ASC, SORT_STRING, 'zip', SORT_DESC, SORT_NUMERIC, $data)
4
ответ дан 10 December 2019 в 02:53
поделиться
Другие вопросы по тегам:

Похожие вопросы: