Cod*_*ver 2 php arrays sorting
我正在尝试使用 php 排序函数按字母顺序对数组进行排序。
Array ( [0] => Open Sans [1] => Wellfleet [2] => Rambla [3] => Dosis [4] => Noto Sans [5] => Domine [6] => Signika Negative [7] => Arvo [8] => Neuton [9] => Rufina [10] => Tinos [11] => Podkova [12] => Magra [13] => Bitter [14] => Anton [15] => Libre Baskerville [16] => Tienne [17] => Roboto [18] => Ruda [19] => Merriweather [20] => Amaranth [21] => Playfair Display SC [22] => Cinzel Decorative [23] => Nobile [24] => Volkhov [25] => Nunito [26] => Merriweather Sans [27] => Stardos Stencil [28] => Bree Serif )
Run Code Online (Sandbox Code Playgroud)
我试过这个
$heading_fonts = sort($heading_fonts);
Run Code Online (Sandbox Code Playgroud)
最终我组合数组以获得相同的键和值。
$heading_fonts = array_combine($heading_fonts, $heading_fonts);
Run Code Online (Sandbox Code Playgroud)
但给我一个错误。
Warning: array_combine() expects parameter 1 to be array, boolean given in...
Run Code Online (Sandbox Code Playgroud)
知道如何对数组进行排序才能工作吗?
该sort函数将就地对数组进行排序并返回一个布尔值来指示其成功。您不应该将其返回值分配给数组。仅使用:
sort($heading_fonts);
Run Code Online (Sandbox Code Playgroud)