Q:

Sort per same string name and index position

I'm trying to sort an array where I have a column with equals strings, and a previous column with the information that should be print according to occurrence.  I want to print only the alphabetical order of column 9  and do not take in consideration the alphabetical order from column 8. 
For example:
column 9=[rank 1, rank1, rank 2, rank2, rank 3, rank3, ...]

column 8=[CO,      BR,    IR,     AB,    CB,      CA....]

It should give me this  output below, because I want to print by rank 1, rank 2, rank 3, rank 1, rank 2, rank 3:
CO IR CB  BR AB CA

However, my code take the alphabetic order of column 9 when it find equals strings in column 9.  How could I solve.  Is there a way to check the index to display the data in that order? 
here is my code:
function readCsv($fileName){

    $handle = fopen($fileName, "r");

    $data=array();

    while ($col = fgetcsv($handle, 1000, ",")) { 

        $data[] = [

            'Section' => $col[0],   
            'Q #' => $col [1],
            'Q Type' => $col[2],
            'Q Title' => $col[3],
            'Q Text' => $col[4],
            'Bonus' => $col [5],
            'Difficulty' => $col[6],
            'Answer' => $col[7],
            'Answer Match' => $col[8],
            'Responses'=> $col[9], 

        ];      

    }

    unset($data[0]); //skip line 1, header
    usort($data, 'cmp');

    fclose($handle);
    return $data;
}
ob_end_flush();

function cmp($a, $b) {

    return $a['Answer Match'] > $b['Answer Match'] (array_search($a['Answer Match'], $a) < array_search($b['Answer Match'], $b)+1);
}

A:

You could use array_multisort in two passes:

First sort by "Answer Match" and "Responses"
Add a new column to the data: the sequence number within a group of same "Answer Match" values
Sort again, but now by that new column, and then "Answer Match"

Here is the code:
// Example data
$data = [
    ["Answer Match" => "rank 3", "Responses" => "CB"],
    ["Answer Match" => "rank 1", "Responses" => "CO"],
    ["Answer Match" => "rank 1", "Responses" => "BR"],
    ["Answer Match" => "rank 2", "Responses" => "IR"],
    ["Answer Match" => "rank 2", "Responses" => "AB"],
    ["Answer Match" => "rank 3", "Responses" => "CA"],
];

// First sort by "Answer Match" and then "Responses":
array_multisort(array_column($data, "Answer Match"), 
                array_column($data, "Responses"), SORT_DESC, $data);

// Then add a new column to the data, which gives the sequence number 
// within the same group of "Answer Match":
foreach($data as $i => $a) {
    $data[$i]["i"] = (! $i or $a["Answer Match"] ! = $data[$i-1]["Answer Match"]) 
                         ?  1 : $data[$i-1]["i"]+1;
}

// Now sort using that extra column to get the final sort order
array_multisort(array_column($data, "i"), array_column($data, "Answer Match"), $data);

// If it bothers you, the extra column can be removed again.