Associative array, Shorting Arrays and Array data structure

An associative array, Shorting Arrays and Array data structure

Associative array Shorting Arrays and Array data structure:-

therefore short array in ascending or descending order and array element can be stored in numerical or alphabetical order

Sort Functions For Arrays in PHP

Associative array Shorting Arrays and Array data structure image
First of all, In this PHP Shorting Arrays, we will introduce the following PHP array sort functions:

  • sort() –  It used to sort arrays in ascending order
  • rsort() –  Sort arrays in descending order
  • asort() – as a result sort associative arrays in ascending order, according to the value
  • ksort() – In Program sort associative arrays in ascending order, according to the key
  • arsort() -this function we can be used to sort associative arrays in descending order, according to the value
  • krsort() -also used to sort associative arrays in descending order, according to the key

Sort Array in Ascending Order – sort()

This example sorts the elements of the $ colors array in ascending alphabetical order:

 Finally Output:-

Another Example

Sort Array in Descending Order – rsort()

Therefore $cars array in descending alphabetical order:

Finally Output:

 

Resource
PHP.net