简体   繁体   English

php下拉列表排序

[英]php dropdown list sort

I am displaying in a dropdown menu a list of values and the problem is that I cannot sort them.我在下拉菜单中显示了一个值列表,问题是我无法对它们进行排序。

Every option has a value eg dog->15 cat->17 apple->22 chair->32每个选项都有一个值,例如 dog->15 cat->17 apple->22chair->32

I have tried to use the arsort or usort for defined function but nothing works.我曾尝试将 arsort 或 usort 用于定义的函数,但没有任何效果。

Here is the part of displaying the values这是显示值的部分

<div class="categoryselect">
<?php echo $this->lists['catid']; ?>
</div>

And here is where the dropdown is created这是创建下拉列表的地方

$lists['catid']     = JHTML::_('select.genericlist',$category,  'catid', 'class="inputtext" onchange="select_cate(this.value)"  ', 'value', 'text',$cat_id );

As I said I have use user defined sort functions but it seems that only the key value is affected.正如我所说,我使用了用户定义的排序函数,但似乎只有键值受到影响。

Any help is appreciated任何帮助表示赞赏

Thank you谢谢

The sample code below sorts the PHP associative array in ascending order下面的示例代码按升序对 PHP 关联数组进行排序

<div class="categoryselect">
    <?php 
        arsort($this->lists['catid']); // according to value. To sort by key use ksort(lists)
        echo $this->lists['catid']; 
    ?>
</div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM