Bladephp: Now with 7+ codeigniter, php, and laravel project 7+ php project From $18/Year From Rs. 1000/Year

PHP ksort() Function

by
Category:php
php php array function
PHP ksort() Function

The ksort() function sorts an array by key, maintaining key to data correlations. This is useful mainly for associative arrays.

Tip: Use the krsort() function to sort an associative array in descending order, according to the key.

Tip: Use the asort() function to sort an associative array in ascending order, according to the value.

Parameter Description
array Required. Specifies the array to sort
sortingtype Optional. Specifies how to compare the array elements/items. Possible values:

Syntax

ksort(array,sortingtype);

Example

$age=array("Samuel"=>"35","James"=>"37","Cooper"=>"43");
ksort($age);
print_r($age);

Output

Array ( [Cooper] => 43 [James] => 37 [Samuel] => 35 ) 

0 Comments


Html code work in comment box


Related Post