array ksort function - sort the given array by key regular order

array ksort function - sort the given array by key regular order

array-ksort-function-example-in-php.php


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
 <head>
  <title>array ksort function - sort the given array by key regular order</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  <meta name="Author" content="Md Iqbal Hosan">
  <meta name="title" content="array ksort function - sort the given array by key regular order">
  <meta name="keywords" content="php, example, code, array, function, ksort">
  <meta name="description" content="array ksort function - sort the given array by key regular order">
  <style>
   h2, h3, h4{background:#aaa; color:#000059;}
   h2{ padding:3px; margin:3px; font-size:20px;}
   h3{ padding:2px; margin:2px; font-size:17px;}
   h4{ padding:2px; margin:2px; font-size:15px;}
   body{ background:#FFFFFa;}
  </style>
 </head>
 <body>
  <h2>array ksort function - sort the given array by key regular order</h2>
  <pre>
   <?php
    /*
     -----------------------------------------------------------
     les make an array and fill up with some keys and values
     -----------------------------------------------------------
    */
    $myArray = array("a"=>"apple","z"=>"zoo","c"=>"cat","b"=>"book");
    echo "<h4>Output of myArray</h4>";
    print_r($myArray);
    /*
     -------------------------------------------------------------------------------------
     we want to sort the array by using array ksort function
     sorting is based on keys rather than values
     -------------------------------------------------------------------------------------
    */
    ksort($myArray);
    echo "<h4>Output of sorted array using array ksort function by keys</h4>";
    print_r($myArray);
   ?>
  </pre>
 </body>
</html>

array ksort function - sort the given array by key regular order - output in the browser

No comments:

Post a Comment

leave your comments here..