How To Sort In Php


Bạn đang xem: How to sort in php

The elements in an array can be sorted in alphabetical or numerical order, descending or ascending.

PHPhường - Sort Functions For Arrays

In this chapter, we will go through the following PHPhường array sort functions:

sort() - sort arrays in ascending order rsort() - sort arrays in descending order asort() - sort associative sầu arrays in ascending order, according to the value ksort() - sort associative sầu arrays in ascending order, according khổng lồ the key arsort() - sort associative sầu arrays in descending order, according khổng lồ the value krsort() - sort associative sầu arrays in descending order, according to lớn the key

Sort Array in Ascending Order - sort()

The following example sorts the elements of the $cars array in ascending alphabetical order:




Sort Array in Descending Order - rsort()

The following example sorts the elements of the $cars array in descending alphabetical order:




Sort Array (Ascending Order), According to lớn Value - asort()

The following example sorts an associative array in ascending order, according khổng lồ the value:



"35", "Ben"=>"37", "Joe"=>"43"); asort($age);?>

Sort Array (Ascending Order), According to lớn Key - ksort()

The following example sorts an associative sầu array in ascending order, according lớn the key:



"35", "Ben"=>"37", "Joe"=>"43"); ksort($age);?>

Sort Array (Descending Order), According khổng lồ Value - arsort()

The following example sorts an associative sầu array in descending order, according to lớn the value:



Xem thêm: Wq Là Gì ? Nghĩa Của Từ Wq Trong Tiếng Việt Cơ Bản Về Vim Cho Người Mới Bắt Đầu

"35", "Ben"=>"37", "Joe"=>"43"); arsort($age);?>

Sort Array (Descending Order), According khổng lồ Key - krsort()

The following example sorts an associative array in descending order, according khổng lồ the key:



"35", "Ben"=>"37", "Joe"=>"43"); krsort($age);?>

Complete PHP Array Reference

For a complete reference of all array functions, go khổng lồ our complete PHP Array Reference.

The reference contains a brief description, and examples of use, for each function!

PHPhường Exercises

Test Yourself With Exercises


Tabs Dropdowns Accordions Side Navigation Top Navigation Modal Boxes Progress Bars Parallax Login Form HTML Includes Google Maps Range Sliders Tooltips Slideshow Sort List
×

Report Error

If you want to report an error, or if you want lớn make a suggestion, vì not hesitate to sover us an e-mail:

help


Top Tutorials HTML Tutorial CSS Tutorial JavaScript Tutorial How To Tutorial Squốc lộ Tutorial Pybé nhỏ Tutorial W3.CSS Tutorial Bootstrap Tutorial PHPhường Tutorial Java Tutorial C++ Tutorial jQuery Tutorial
Top References HTML Reference CSS Reference JavaScript Reference SQL Reference Pykhông lớn Reference W3.CSS Reference Bootstrap Reference PHPhường Reference HTML Colors Java Reference Angular Reference jQuery Reference
Top Examples HTML Examples CSS Examples JavaScript Examples How To Examples SQL Examples Pykhiêm tốn Examples W3.CSS Examples Bootstrap Examples PHP Examples Java Examples XML Examples jQuery Examples
Web Courses HTML Course CSS Course JavaScript Course Front End Course SQL Course Python Course PHP Course jQuery Course Java Course C++ Course C# Course XML Course Get Certified »
obatambeienwasirherbal.com is optimized for learning and training. Examples might be simplified khổng lồ improve sầu reading and learning. Tutorials, references, and examples are constantly reviewed khổng lồ avoid errors, but we cannot warrant full correctness of all nội dung. While using obatambeienwasirherbal.com, you agree lớn have sầu read và accepted our terms of use, cookie & privacy policy. Copyright 1999-2021 by Refsnes Data. All Rights Reserved. obatambeienwasirherbal.com is Powered by W3.CSS.

*