PHP - Sorting Associative Arrays with asort() and arsort()

Introduction

asort() and arsort() work like sort() and rsort(), but they preserve the association between each element's key and its value:

Demo

<?php
         $myBook = array("title"=> "PHP",
                         "author"=> "D",
                         "year"=>  2018);

         asort($myBook);/*from  w  ww  .j a v  a2  s.  c  om*/
         print_r($myBook);

         arsort($myBook);
         print_r($myBook);
?>

Result

Related Topic