<?php
$fruits = array("lemon", "orange", "banana", "apple");
rsort($fruits);
foreach ($fruits as $key => $val) {
echo "$key = $val
";
}
?>
<?php
$fruits = array("lemon", "orange", "banana", "apple");
sort($fruits);
foreach ($fruits as $key => $val) {
echo $val;
}
/*
OUTPUT:
apple
banana
lemon
orange
*/
?>
<?php
$fruits = array("Zitrone", "Orange", "Banane", "Apfel");
sort($fruits);
foreach ($fruits as $key => $val) {
echo "fruits[" . $key . "] = " . $val . "
";
}
?>
sort() - sort arrays in ascending order
rsort() - sort arrays in descending order
asort() - sort associative arrays in ascending order, according to the value
ksort() - sort associative arrays in ascending order, according to the key
arsort() - sort associative arrays in descending order, according to the value
krsort() - sort associative arrays in descending order, according to the key
function aasort (&$array, $key) {
$sorter=array();
$ret=array();
reset($array);
foreach ($array as $ii => $va) {
$sorter[$ii]=$va[$key];
}
asort($sorter);
foreach ($sorter as $ii => $va) {
$ret[$ii]=$array[$ii];
}
$array=$ret;
}
aasort($your_array,"order");
<?php
$array = array("id" => 8, "id" =>1, "id" =>3, "id"=>2, "id" => 12, "id" =>19);
print_r($array->orderBy("id"));
?>
// Fonction de comparaison
function cmp($a, $b) {
if ($a == $b) {
return 0;
}
return ($a < $b) ? -1 : 1;
}
$array_temp_id = array_column($companions, 'temp_id');
array_multisort($array_temp_id, SORT_DESC, $companions);
PHP function sort(array &$array, int $flags) bool
---------------------------------------------
Sort an array
Parameters:
array--$array--The input array.
int--$flags--[optional] The optional second parameter sort_flags may be used to modify the sorting behavior using these values.
Sorting type flags: SORT_REGULAR - compare items normally (don't change types).
Returns: true on success or false on failure.
Code Example |
---|
:: |
:: |
:: |
Php :: |
:: |
:: |
Php :: |
Php :: |
:: |
Php :: |
Php :: laravel require vendor autoload |
:: minus day from carbon date |
Php :: |
Php :: |
Php :: |
:: |
:: php loop object |
:: mpdf output |
:: |
Php :: |
:: LARAVEL CREAT NEW TEST |
Php :: |
:: |
:: |
:: |
:: |
:: |
:: |
Php :: |
:: |