Sort associative array in ascending order in PHP according to key

How to sort associative array by key in php.

android-project-download-code-button

Code for array-sort-by-key.php file.

 <!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Sort associative array by key</title>
</head>

<body>

<?php
$marks = array("Ram"=>"99", "Shyam"=>"90", "Mukesh"=>"80");
ksort($marks);

foreach($marks as $i => $i_marks) {
 
 echo "Key = " . $i . ", Marks = " . $i_marks ."</br>" ;
 
}
?>

</body>
</html>

Screenshot:

 Sort associative array in ascending order in PHP according to key

Click here to download  Sort associative array in ascending order in PHP according to key project file with source code.

Leave a Reply

Your email address will not be published. Required fields are marked *