ksort()
and krsort()
functionThe PHP ksort()
and krsort()
functions can be used for sorting an array by key. The following section will show you how these functions basically work.
You can use the ksort()
function for sorting an associative array by key alphabetically in the ascending order, while maintaining the relationship between key and data.
<?php
$fruits = array("b"=>"banana", "a"=>"apple", "d"=>"dog", "c"=>"cat");
// Sorting the array by key
ksort($fruits);
print_r($fruits);
?>
You can use the krsort()
function for sorting an associative array by key alphabetically in the descending order, while maintaining the relationship between key and data.
<?php
$fruits = array("b"=>"banana", "a"=>"apple", "d"=>"dog", "c"=>"cat");
// Sorting the array by key
krsort($fruits);
print_r($fruits);
?>
Hi, My name is Harsukh Makwana. i have been work with many programming language like php, python, javascript, node, react, anguler, etc.. since last 5 year. if you have any issue or want me hire then contact me on [email protected]
Disable Text Selection In WebPage Using jQuery and CSS
Many times you need to prevent text sele...Create Fake Data using Faker and Factory in Laravel 8
In the process of building application,...Fix recovery pending state in SQL server database
When you can't access one or multipl...How to detect click inside iframe using JavaScript
Use the jQuery contents() method If y...How to Export whole table to CSV using laravel
In this article, i will share with you h...