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   ww w.j a v a2s . co  m*/
         print_r($myBook);

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

Result

Related Topic