ArrayObject::natcasesort


Sort entries using a case insensitive natural order algorithm.



<?php

void 
public ArrayObject::natcasesort void )

?>

 ATTENTION 


This method implements a sort algorithm that orders alphanumeric strings in the way a human being would while maintaining key/value associations, described as a natural ordering.

This method is a case insensitive version of ArrayObject::natsort.



  1 EXERCISE   

<?php

$Dwarfs 
= [ => 'Bashful'=> 'Doc'
                  
=> 'Grumpy'=> 'Happy'
                  
=> 'Sneezy'=> 'Sleepy'=> 'Dopey'];

$dwArrayObject = new ArrayObject($Dwarfs);

$dwArrayObject->natcasesort();

foreach(
$dwArrayObject as $dw => $dwc)
{
echo 
'[ ' $dw ' ] - ';
var_dump($dw$dwc);
echo 
'<br><br>';
}

?>

 RESULT   

[ 1 ] - int(1) string(7) "Bashful"

[ 2 ] - int(2) string(3) "Doc"

[ 7 ] - int(3) string(6) "Grumpy"

[ 3 ] - int(4) string(5) "Happy"

[ 4 ] - int(5) string(6) "Sneezy"

[ 6 ] - int(6) string(6) "Sleepy"

[ 5 ] - int(7) string(5) "Dopey"


  2 EXERCISE   

<?php

$Conts 
= [ 'c' => 299792458'G' => 6.67428E-11 ];  

$ctArrayObject = new ArrayObject($Conts);

$ctArrayObject->natcasesort();

foreach(
$ctArrayObject as $ct => $ctc)
{
echo 
'[ ' $ct ' ] - ';
var_dump($ct$ctc);
echo 
'<br><br>';
}

?>

 RESULT   

[ G ] - string(1) "G" float(6.67428E-11)

[ c ] - string(1) "c" int(299792458)


  3 EXERCISE   

<?php

$nmValues 
= [ 23413022, -120.234569.999 ];  

$nmArrayObject = new ArrayObject($nmValues);

$nmArrayObject->natcasesort();

foreach(
$nmArrayObject as $nm => $nmc)
{
echo 
'[ ' $nm ' ] - ';
var_dump($nm$nmc);
echo 
'<br><br>';
}

?>

 RESULT   

[ 3 ] - int(3) int(-12)

[ 4 ] - int(4) float(0.23456)

[ 5 ] - int(5) float(9.999)

[ 2 ] - int(2) int(22)

[ 1 ] - int(1) int(130)

[ 0 ] - int(0) int(234)


  4 EXERCISE   

<?php

$mvValues 
= [ 'two hundred thirty-four'234
                      
'One hundred and thirty'130
                      
'minus one hundred and twelve', -12
                      
'Nine point nine hundred and ninety nine'9.999 ];  

$mvArrayObject = new ArrayObject($mvValues);

$mvArrayObject->natcasesort();

foreach(
$mvArrayObject as $mv => $mvc)
{
echo 
'[ ' $mv ' ] - ';
var_dump($mv$mvc);
echo 
'<br><br>';
}

?>

 RESULT   

[ 5 ] - int(5) int(-12)

[ 7 ] - int(7) float(9.999)

[ 3 ] - int(3) int(130)

[ 1 ] - int(1) int(234)

[ 4 ] - int(4) string(28) "minus one hundred and twelve"

[ 6 ] - int(6) string(39) "Nine point nine hundred and ninety nine"

[ 2 ] - int(2) string(22) "One hundred and thirty"

[ 0 ] - int(0) string(23) "two hundred thirty-four"


  5 EXERCISE   

<?php

$ovValues 
= [ 123=> 'x'=> 'X'=> 'b'=> 'c'=> 'A' ];  

$ovArrayObject = new ArrayObject($ovValues);

$ovArrayObject->natcasesort();

foreach(
$ovArrayObject as $ov => $ovc)
{
echo 
'[ ' $ov ' ] - ';
var_dump($ov$ovc);
echo 
'<br><br>';
}

?>

 RESULT   

[ 0 ] - int(0) int(1)

[ 1 ] - int(1) int(2)

[ 2 ] - int(2) int(3)

[ 7 ] - int(7) string(1) "A"

[ 4 ] - int(4) string(1) "b"

[ 5 ] - int(5) string(1) "c"

[ 3 ] - int(3) string(1) "x"

[ 6 ] - int(6) string(1) "X"


  6 EXERCISE   

<?php

$otValues 
= [ 'one''two''three''FOUR''Five'];

$pvValues = [ 123, ...$otValues ];  

/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

        The Unpacking inside arrays: 
              ...$otValues, 
        was introduced in PHP 7.4.0 

   - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

$pvArrayObject = new ArrayObject($pvValues);

$pvArrayObject->natcasesort();

foreach(
$pvArrayObject as $pv => $pvc)
{
echo 
'[ ' $pv ' ] - ';
var_dump($pv$pvc);
echo 
'<br><br>';
}

?>

 RESULT   

[ 0 ] - int(0) int(1)

[ 1 ] - int(1) int(2)

[ 2 ] - int(2) int(3)

[ 7 ] - int(7) string(4) "Five"

[ 6 ] - int(6) string(4) "FOUR"

[ 3 ] - int(3) string(3) "one"

[ 5 ] - int(5) string(5) "three"

[ 4 ] - int(4) string(3) "two"