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, ∼2383🔥, 0💬
Popular Posts:
How To Merge Cells in a Column? If you want to merge multiple cells vertically in a row, you need to...
How to use the "set-body" Policy Statement for an Azure API service operation? The "set-body" Policy...
How to add request query string Parameters to my Azure API operation 2017 version to make it more us...
How to add images to my EPUB books Images can be added into book content using the XHTML "img" eleme...
How To Break a File Path Name into Parts in PHP? If you have a file name, and want to get different ...