Tools, FAQ, Tutorials:
Sorting an Array by Keys in PHP
How To Sort an Array by Keys in PHP?
✍: FYIcenter.com
Sorting an array by keys can be done by using the ksort() function. It will re-order all pairs of keys and values based on the alphanumeric order of the keys. Here is a PHP script on how to use ksort():
<?php
$mixed = array();
$mixed["Zero"] = "PHP";
$mixed[1] = "Perl";
$mixed["Two"] = "Java";
$mixed["3"] = "C+";
$mixed[""] = "Basic";
$mixed[] = "Pascal";
$mixed[] = "FORTRAN";
ksort($mixed);
print("Sorted by keys:\n");
print_r($mixed);
?>
This script will print:
Sorted by keys:
Array
(
[] => Basic
[Two] => Java
[Zero] => PHP
[1] => Perl
[3] => C+
[4] => Pascal
[5] => FORTRAN
)
⇒ Sorting an Array by Values in PHP
⇐ Retrieving All Values from an Array in PHP
2017-01-21, ∼2559🔥, 0💬
Popular Posts:
How to make application release build with Visual Studio 2017? If you want to make a final release b...
How To Copy Array Values to a List of Variables in PHP? If you want copy all values of an array to a...
How to use .NET CLR Types in Azure API Policy? By default, Azure imports many basic .NET CLR (Common...
Where to find tutorials on RSS specifications? I want to learn it to describe my API services. Here ...
How to create a new API on the Publisher Dashboard of an Azure API Management Service? If you are ne...