Массив вида значением в алфавитном порядке php

Вы могли отправить HTTP-заголовки, чтобы препятствовать тому, чтобы он кэшировался:

Cache-control: no-cache
Pragma: no-cache

, Как Вы, это зависит от веб-сервера, который Вы используете.

38
задан dotty 4 November 2009 в 11:37
поделиться

3 ответа

You want the php function "asort":

http://php.net/manual/en/function.asort.php

it sorts the array, maintaining the index associations.

Edit: I've just noticed you're using a standard array (non-associative). if you're not fussed about preserving index associations, use sort():

http://php.net/manual/en/function.sort.php

48
ответ дан 27 November 2019 в 03:26
поделиться

Обратите внимание, что sort () работает с массивом вместо , поэтому вам нужно только вызвать

sort($a);
doSomething($a);

. Это не сработает;

$a = sort($a);
doSomething($a);
26
ответ дан 27 November 2019 в 03:26
поделиться
  • If you just want to sort the array values and don't care for the keys, use sort(). This will give a new array with numeric keys starting from 0.
  • If you want to keep the key-value associations, use asort().

See also the comparison table of sorting functions in PHP.

7
ответ дан 27 November 2019 в 03:26
поделиться
Другие вопросы по тегам:

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