PHP

PHP Menu

PHP

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

Definition

The sort() function sorts an indexed array in ascending order.

Syntax

sort(array, sorttype)

Parameters

Parameter Description
array Required. Specifies the array to sort.
sorttype Optional. Possible values:
0 = SORT_REGULAR - Default. Compare items normally (don't change types)
1 = SORT_NUMERIC - Compare items numerically
2 = SORT_STRING - Compare items as strings
3 = SORT_LOCALE_STRING - Compare items as strings, based on current locale
4 = SORT_NATURAL - Compare items as strings using natural ordering
5 = SORT_FLAG_CASE - Can be combined (bitwise OR) with SORT_STRING or SORT_NATURAL to sort strings case-insensitively

Example

<?php
$cities = array("New York", "London", "Tokyo", "Berlin", "Cairo"); sort($cities); print_r($cities);

Introduction

PHP Basics

PHP Advance

PHP OOP

PHP Functions and Methods