Answers for "php sort()"

PHP
1

php sorting functions

<?php
$fruit = array("apple","banana","mango","orange","strawbary");

sort($fruit);       //arrange in ascending order
echo "<pre>";
print_r($fruit);

rsort( $fruit);     //sort in descending order
foreach($fruit as $val)
{
    echo $val."<br>";
}

$girl = array("krisha"=>20,"yashvi"=>30,"ritu"=>4,"pinal"=>80);
asort($girl);       //sort in ascending order according to value
print_r($girl);

ksort($girl);   //sort in ascending order according to key
print_r($girl);     

arsort($girl);      //sort in descending order according to value
print_r($girl);

krsort($girl);      //sort in descending order according to key
print_r($girl);
?>
Posted by: Guest on September-06-2021
2

php sort array by value

$price = array();
foreach ($inventory as $key => $row)
{
    $price[$key] = $row['price'];
}
array_multisort($price, SORT_DESC, $inventory);
Posted by: Guest on June-19-2021
0

array sort php

<?php

$fruits = array("lemon", "orange", "banana", "apple");
sort($fruits);
foreach ($fruits as $key => $val) {
    echo $val;
}
/*
OUTPUT:
apple
banana
lemon
orange
*/
?>
Posted by: Guest on May-14-2020
1

php sort()

<?php

$fruits = array("Zitrone", "Orange", "Banane", "Apfel");
sort($fruits);
foreach ($fruits as $key => $val) {
    echo "fruits[" . $key . "] = " . $val . "\n";
}

?>
Posted by: Guest on May-15-2020

Browse Popular Code Answers by Language