当前位置:网站首页>PHP uasort() function

PHP uasort() function

2022-06-24 05:10:00 User 1448800

example

Use the user-defined comparison function to compare the array $arr The key values of the elements in the :

<?php
function my_sort($a,$b)
{
if ($a==$b) return 0;
return ($a<$b)?-1:1;
}

$arr=array("a"=>4,"b"=>2,"c"=>8,d=>"6");
uasort($arr,"my_sort");
?>

Definition and Usage

uasort() Function to sort an array using a user-defined comparison function , And keep index Association ( Don't assign new keys to elements ).

Return if successful TRUE, Otherwise return to FALSE.

This function is mainly used to sort the associative arrays whose cell order is very important .

grammar

uasort(array,myfunction);

Parameters

describe

array

It's necessary . Specify the array to sort .

myfunction

Optional . Define the string that can call the comparison function . If the first parameter is less than or equal to or greater than the second parameter , Then the comparison function must return a value less than or equal to or greater than 0 The integer of .

Technical details

Return value :

Return if successful TRUE, If it fails, return to FALSE.

PHP edition :

4+

原网站

版权声明
本文为[User 1448800]所创,转载请带上原文链接,感谢
https://yzsam.com/2021/08/20210822001432233t.html