使用升序/降序php

时间:2016-06-06 15:10:34

标签: php sorting

在以下函数中,表格正确地为我们提供了,如何排序 ,对,知道代码中没有排序:

public function render_car_bookings($items) {
        $out = '';

        $bookings = $items->get_bookings();
        $out .= 'List with bookings';
        $out .= $this->output->paging_bar($items->get_total_count(), $items->get_page(),
                                          $items->get_perpage(), $items->get_url());

        $table = new html_table();
        $table->head = array(
            'Car name',
            'Plate number',
            'Production year',
            'Booking date',
            'City',
        );
        $table->data = array();

        $strdateformat = get_string('strftimedate');
        $strtimeformat = get_string('strftimetime');
        foreach ($bookings as $booking) {
            $platedatestart = userdate($booking->starttime, $strdateformat);
            $platedateend = userdate($booking->endtime, $strdateformat);
            $bookingtimestart = userdate($booking->starttime, $strtimeformat);
            $bookingtimefinish = userdate($booking->endtime, $strtimeformat);

            $date = $platedatestart;
            if ($platedatestart != $platedateend) {
                $date .= ' - '.$platedateend;
            }
            $time = $bookingtimestart.' - '.$bookingtimefinish;

            $row = array(
                format_string($booking->carname),
                format_string($booking->shortnamecar),
                $date,
                $time,
                format_string($booking->city),
            );
            $table->data[] = $row;
        }

        $out .= html_writer::table($table);

        return $out;
    }

该表如下所示:

    | Carname | Plate number | Production year | Booking date | City |
    ----------+--------------+-----------------+--------------+------

是否也可以在php中添加排序功能所需的所有代码,即从上面的函数中添加?

0 个答案:

没有答案