php sort array by key
$weight = [
'Pete' => 75,
'Benjamin' => 89,
'Jonathan' => 101
];
ksort($weight);
php sort array by key
$weight = [
'Pete' => 75,
'Benjamin' => 89,
'Jonathan' => 101
];
ksort($weight);
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);
?>
php sort reverse
<?php
$fruits = array("lemon", "orange", "banana", "apple");
rsort($fruits);
foreach ($fruits as $key => $val) {
echo "$key = $val\n";
}
?>
sort array php
<?php
$fruits = array("d" => "lemon", "a" => "orange", "b" => "banana", "c" => "apple");
asort($fruits);
foreach ($fruits as $key => $val) {
echo "$key = $val\n";
}
?>
//Would output:
c = apple
b = banana
d = lemon
a = orange
php sort hight to low
$letters=array("b","a","c");
arsort($letters); //referse sort an array ("c","a","b")
array sort php
<?php
$fruits = array("lemon", "orange", "banana", "apple");
sort($fruits);
foreach ($fruits as $key => $val) {
echo $val;
}
/*
OUTPUT:
apple
banana
lemon
orange
*/
?>
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us