PHP

PHP Menu

PHP

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

Definition

The uksort() function sorts an array by keys using a user-defined comparison function.

Syntax

uksort(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); uksort($array, "compare"); print_r($array);

Introduction

PHP Basics

PHP Advance

PHP OOP

PHP Functions and Methods