PHP

PHP Menu

PHP

uasort() Function - Definition, Syntax, Parameters, Examples

Definition

The uasort() function sorts an array by values using a user-defined comparison function.

Syntax

uasort(array, function)

Parameters

Parameter Description
array Required. Specifies the array to sort.
function Optional. A string that define a callable comparison function. The comparison function must return an integer <, =, or > than 0 if the first argument is <, =, or > than the second argument.

Example

<?php
function compare($x, $y) { if ($x == $y) { return 0; } return ($x < $y) ? -1 : 1; } $array = array("a" => 3, "b" => 1, "c" => 8, "d" => -1, "e" => 7, "f" => -9); uasort($array, "compare"); print_r($array);

Introduction

PHP Basics

PHP Advance

PHP OOP

PHP Functions and Methods