PHP

PHP Menu

PHP

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

Definition

The asort() function sorts an associative array in ascending order, according to the value.

Syntax

asort(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
$ages = array("Mark" => 22, "Jeff" => 32, "Mike" => 28);
asort($ages); print_r($ages);

Introduction

PHP Basics

PHP Advance

PHP OOP

PHP Functions and Methods