068 - sort , Array Sorting with values nameArray
(
[0] => apple
[1] => banana
[2] => grapes
[3] => orange
)
068-a - rsort , Reverse ,reverse Sorting Array
(
[0] => orange
[1] => grapes
[2] => banana
[3] => apple
)
068-b - rsort, Reverse with Numerical Index arrayArray
(
[0] => 64
[1] => 22
[2] => 15
[3] => 3
)
068-c - sort, Associative ArrayArray
(
[0] => apple
[1] => banana
[2] => lemon
[3] => orange
)
068-d - asort, Associative Array with index alsoArray
(
[c] => apple
[b] => banana
[d] => lemon
[a] => orange
)
068-e - arsort, associative reverse sortArray
(
[a] => orange
[d] => lemon
[b] => banana
[c] => apple
)
068-f - krsort, Key Reverse SortArray
(
[a] => orange
[b] => banana
[c] => apple
[d] => lemon
)
Array
(
[d] => lemon
[c] => apple
[b] => banana
[a] => orange
)
068-g - natsort, Natural Order Sort, if all value has same name but different at endArray
(
[3] => img1.png
[2] => img2.png
[1] => img10.png
[0] => img12.png
)
068-h - natcasesort(), - case incentive natural order algorithmArray
(
[3] => img1.png
[2] => img2.png
[1] => Img10.png
[0] => Img12.png
)
068-i - array_multisort, change multiple array , not create new arrayArray
(
[0] => banana
[1] => orange
)
Array
(
[0] => carrot
[1] => lemon
)
068-i - array_reverse, simple reverse the array orderArray
(
[0] => grapes
[1] => apple
[2] => banana
[3] => orange
)
<?php
// 068 - sort , Array Sorting with values name
echo "</br><span class='myheading'>068 - sort , Array Sorting with values name</span></br>";
$food = array('orange', 'banana', 'grapes', 'apple');
sort($food); //Sorting
echo "<pre>";
print_r($food);
echo "</pre>";
// 068-a - rsort , Reverse ,reverse Sorting
echo "</br><span class='myheading'>068-a - rsort , Reverse ,reverse Sorting </span></br>";
$food = array('orange', 'banana', 'grapes', 'apple');
rsort($food);
echo "<pre>";
print_r($food);
echo "</pre>";
// 068-b - rsort, Reverse with Numerical Index array
echo "</br><span class='myheading'>068-b - rsort, Reverse with Numerical Index array</span></br>";
$food1 = [22,15,3,64];
rsort($food1);
echo "<pre>";
print_r($food1);
echo "</pre>";
// 068-c - sort, Associative Array
echo "</br><span class='myheading'>068-c - sort, Associative Array</span></br>";
$food2 = array("d" => "lemon",
"a" => "orange",
"b" => "banana",
"c" => "apple"
);
sort($food2);
echo "<pre>";
print_r($food2);
echo "</pre>";
// 068-d - asort, Associative Array with index also
echo "</br><span class='myheading'>068-d - asort, Associative Array with index also</span></br>";
$food3 = array("d" => "lemon",
"a" => "orange",
"b" => "banana",
"c" => "apple"
);
asort($food3); //---- maintain also index
echo "<pre>";
print_r($food3);
echo "</pre>";
// 068-e - arsort, associative reverse sort
echo "</br><span class='myheading'>068-e - arsort, associative reverse sort</span></br>";
$food3 = array("d" => "lemon",
"a" => "orange",
"b" => "banana",
"c" => "apple"
);
arsort($food3);
echo "<pre>";
print_r($food3);
echo "</pre>";
// 068-f - krsort, Key Reverse Sort
echo "</br><span class='myheading'>068-f - krsort, Key Reverse Sort</span></br>";
$food3 = array("d" => "lemon",
"a" => "orange",
"b" => "banana",
"c" => "apple"
);
ksort($food3);
echo "<pre>";
print_r($food3);
echo "</pre>";
krsort($food3);
echo "<pre>";
print_r($food3);
echo "</pre>";
// 068-g - natsort, Natural Order Sort, if all value has same name but different at end
echo "</br><span class='myheading'>068-g - natsort, Natural Order Sort, if all value has same name but different at end</span></br>";
$array1 = array("img12.png", "img10.png", "img2.png", "img1.png");
natsort($array1);
echo "<pre>";
print_r($array1);
echo "</pre>";
// 068-h - natcasesort(), - case incentive "natural order" algorithm
echo "</br><span class='myheading'>068-h - natcasesort(), - case incentive natural order algorithm</span></br>";
$array2 = array("Img12.png", "Img10.png", "img2.png", "img1.png");
natcasesort($array2);
echo "<pre>";
print_r($array2);
echo "</pre>";
// 068-i - array_multisort, change multiple array , not create new array
echo "</br><span class='myheading'>068-i - array_multisort, change multiple array , not create new array</span></br>";
$foods = array("orange","banana");
$veggie = array("lemon","carrot");
array_multisort($foods,$veggie);
echo "<pre>";
print_r($foods);
echo "</pre>";
echo "<pre>";
print_r($veggie);
echo "</pre>";
// 068-i - array_reverse, simple reverse the array order
echo "</br><span class='myheading'>068-i - array_reverse, simple reverse the array order</span></br>";
$foods1 = array("orange","banana","apple","grapes");
$newArray = array_reverse($foods1);
echo "<pre>";
print_r($newArray);
echo "</pre>";
?>