Thursday 9 October 2014

What is difference between natcasesort and sort?

What is difference between natcasesort and sort?


Question: What is difference between natcasesort and sort?
$arrayData1 = $arrayData2 = array('Test1', 'Test10', 'Test20', 'Test30', 'Test00', 'Test5');

sort($arrayData1);
echo "Standard sorting\n";
print_r($arrayData1);

natcasesort($arrayData2);
echo "\nnatcasesort Sorting\n";
print_r($arrayData2);

Output
Standard sorting
Array
(
    [0] => Test00
    [1] => Test1
    [2] => Test10
    [3] => Test20
    [4] => Test30
    [5] => Test5
)

natcasesort Sorting
Array
(
    [4] => Test00
    [0] => Test1
    [5] => Test5
    [1] => Test10
    [2] => Test20
    [3] => Test30
)