Sort array by value alphabetically php

前端 未结 4 1950
我在风中等你
我在风中等你 2020-12-04 01:39

As the title suggests i want to sort an array by value alphabetically in php.

$arr = array(
    \'k\' => \'pig\',
    \'e\' => \'dog\'
)
4条回答
  •  自闭症患者
    2020-12-04 02:01

    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

提交回复
热议问题