array sort by value in php

Today, We want to share with you array sort by value in php.In this post we will show you php sort multidimensional array by value alphabetically, hear for php sort multidimensional array by value descending we will give you demo and example for implement.In this post, we will learn about PHP Sorting Arrays Tutorial With Examples with an example.

PHP Sorting Arrays

PHP – Sort Functions For Arrays

  • sort() – ascending order
  • rsort() – descending order
  • asort() – ascending order, using to the value
  • ksort() – ascending order, using to the key
  • arsort() – descending order, using to the value
  • krsort() – descending order, using to the key
Read Also:  PHP Sorting Arrays Tutorial With Examples

Sort Array in Ascending Order – sort()

<?php
$members = array("Bhavik", "Rekha", "Dipti");
sort($members);
?>

<?php
$player_rank = array(4, 6, 2, 22, 11);
sort($player_rank);
?>

Sort Array in Descending Order – rsort()

<?php
$members = array("Mayur", "Hitesh", "Ravi");
rsort($members);
?>

<?php
$player_rank = array(4, 6, 2, 22, 11);
rsort($player_rank);
?>

Sort Array (Ascending Order), According to Value – asort()

<?php
$level = array("Krishna"=>"35", "Sejal"=>"37", "Jagruti"=>"43");
asort($level);
?>

Sort Array (Ascending Order), According to Key – ksort()

<?php
$level = array("Krishna"=>"35", "Sejal"=>"37", "Jagruti"=>"43");
ksort($level);
?>

Sort Array (Descending Order), According to Value – arsort()

<?php
$level = array("Krishna"=>"35", "Sejal"=>"37", "Jagruti"=>"43");
arsort($level);
?>

Sort Array (Descending Order), According to Key – krsort()

<?php
$level = array("Krishna"=>"35", "Sejal"=>"37", "Jagruti"=>"43");
krsort($level);
?>

using krsort():

<?php  	
  $weight = [
    'Parash' => 75,
    'Sejaljamin' => 89,
    'Girdhar' => 101
  ];
  krsort($weight);
?>

use ksort() for an ascending order:

<?php  	
  $weight = [
    'Parash' => 75, 
    'Sejaljamin' => 89,
    'Girdhar' => 101
  ];  	
  ksort($weight);
?>

I hope you get an idea about array sort by value in php.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.