Array function library: Usort

Source: Internet
Author: User
Keywords PHP Chinese function Manual Usort array function library
Tags aliyun array array function library function function library function will be functions html

Usort

(PHP3 >= 3.0.3, PHP4)

Usort---&http://www.aliyun.com/zixun/aggregation/37954.html ">nbsp; Sort the values of an array by user-defined functions

Syntax: void Usort (array array, function cmp_function);

Description:

This function will reorder the values of the array according to the function defined by the user.

Example:

<?php

function cmp ($a, $b) {

if ($a = = $b) return 0;

return ($a > $b) -1:1;
}

$a = array (3,2,5,6,1);

Usort ($a, CMP);

while (the list ($key, $value) = each ($a)) {
echo "$key: $value \ n";

}

?>

The results of this example will produce:

0:6 1:5 2:3 3:2 4:1

Reference: Uasort () Uksort () sort () Asort () Arsort () Ksort () Rsort ()

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.