按字母顺序排列foreach的输出


Arranging the output of a foreach alphabetically

如何按字母顺序排列表中foreach循环的输出:

<table class="list <?php echo $list_class; ?>">
<tr class="table-header">
<?php
if (is_array($columns)):
    foreach ($columns as $column):
        $column = parse_class($column);
?>
        <th class="<?php echo $column['class']; ?>"><?php echo $column['column']; ?></th>
<?php
    endforeach;
endif;
if (is_array($actions)):
    foreach ($actions as $action): ?>
    <th class="action"></th>
<?php
    endforeach;
endif;
?>
</tr>

<?php
if (is_array($data['page'])):
    foreach ($data['page'] as $item):
        foreach($item as $item_member):
            if(stripos($item_member, $_POST['term']) !== FALSE):
?>
                <tr>
<?php
                foreach ($columns as $key => $column):
                    $key = parse_class($key);
?>
                    <td class="<?php echo $key['class']; ?>"><a class="cell-link" href="<?php echo $details_link . $item[$details_id_field]; ?>">
<?php
                    echo (!empty($item[$key['column']])) ? $item[$key['column']] : '&nbsp;';
?>
                    </a></td>
<?php
                endforeach;
?>
                </tr>
<?php
            endif;
        endforeach;
    endforeach;
endif;
?>
</table>

我正在努力确保第一列是按字母顺序排列的。我可以在第一个循环中应用一些东西吗?感谢

您可以使用PHP排序函数:

sort ( $columns ); 

点击此处了解更多信息:http://php.net/sort