Current code --
<?php
$arrunsort = array('ab','ad','ar','cd','cb','sc','si','wa','za');
$prevLabel = array();
$currLabelarr = array();
foreach( $arrunsort as $sortelem )
{
$currLabel = substr($sortelem, 0, 1);
if( $currLabel !== $prevLabel )
{
$currLabelarr[] = $currLabel;
$prevLabel[] = $currLabel;
}
}
echo "<pre>";
print_r($currLabelarr);
Output-
Array
(
[0] => a
[1] => a
[2] => a
[3] => c
[4] => c
[5] => s
[6] => s
[7] => w
[8] => z
)
My expected output from the code -
Array
(
[0] => a
[1] => c
[2] => s
[3] => w
[4] => z
)
I know I can use array_unique() with this array, but how do I manage it from the above code as output from array_unique looks not too good.
output from print_r(array_unique($currLabelarr));
Array
(
[0] => a
[3] => c
[5] => s
[7] => w
[8] => z
)