CopyPastehas never been so tasty!

Sort array in reverse order to maintain index association in

by anonymous

  • 0
  • 0
  • 0
78 views

http://codingvilla.com/sort-array-reverse-order-php-single-article-656.aspx

 

 

Arrays:

 

Arrays are just like the variable that store values but we can use arrays to store more than one value. Variable only store one value. There are three types of arrays

 

 

  • Numeric arrays
  • Associative array
  • Multidimensional array

 

Sorting:

 

Sorting is a technique for the arrangement of element in a particular sequence. We can sort in ascending and descending order.

 

arsort () function in php:

 

This function is used to sort array in reverse order and keep their original values.

 

Syntax:

 

arsort(array,sorttype)

 

Reverse sort using arsort () function in php:

 

To sort function in reverse order we use arsort () function in php. Arsort () is a built-in function in php. This function takes array and type of sort as parameter and return sorted array in specific order.

 

Code:

 

<?php

$states = array("Delaware","Pennsylvania","New Jersey");

   arsort($states);

   print_r($states);

?>

 

Above is a simple code to sort an array in reverse order for maintaining index association in PHP.

 

This simple article tells that how we sort an array in reverse order for maintaining index association in PHP.

Add A Comment: