I have lots of emails imported from txt file:
   $emails = file("exported_addresses.txt");
   $c = count($emails);
   for ( $i=0; $i<$c ; $i++ )
      $emails[$i] = strtolower(trim($emails[$i]));
   $portions = array();
   // $c = count($emails);
   for ( $i=0; $i<$c ; $i++ ):
     $sub = substr($emails[$i],0,2);
     if ( strlen($sub)==2 ) // e.g a1
       $sub .= $sub[0]." ";
     if ( !isset( $sub, $portions) ) 
       $portions[$sub] = array();
     $portions[$sub][] = $emails[$i];
   endfor;
   print_r($portions);die;
And I would like to sort the array in ascending order in both levels so this:
array( ['ma'] = array(
'martinu@yahoo.com',
'martina@post.com',
'marti@nette.com'),
['du'] = array(
'durkac@email.com',
'durek@net.com',
'dundy@gmail.com') )
woudl become this:
array(
['du'] = array(
'dundy@gmail.com',
'durek@net.com',
'durkac@email.com' ),
['ma'] = array(
'marti@nette.com',
'martina@post.com',
'martinu'@yahoo.com' )
 )
I could not find such example how to archieve this. It is not clear to me if can I use array_multisort or do I need to write my own callback function. If usort is required can you give an example how to sort this?
Edit: I expect allowed chars in both levels are based on https://www.rfc-editor.org/rfc/rfc5322
ALPHA / DIGIT /    ; Printable US-ASCII
                       "!" / "#" /        ;  characters not including
                       "$" / "%" /        ;  specials.  Used for atoms.
                       "&" / "'" /
                       "*" / "+" /
                       "-" / "/" /
                       "=" / "?" /
                       "^" / "_" /
                       "`" / "{" /
                       "|" / "}" /
                       "~"
For my purposes I need only the two chars to be sorted.
 
     
     
    