PHP排序数组通过个性化订单

I need to sort an array, I've done this before but it has been easy because the array had numbers or letters to sort in ascedning/descending or alphabetical order.. In this case i have an array of which each element has 3 values, eg:

array[0]=code=1234
        =description='example array'
        =orderCode=P

array[1]=code=1235
        =description='example array1'
        =orderCode=A
.
.
.

Now i need to order theese reading the orderCode value in this order: P,I,B,C,A,S,D. The way i thought of getting arround it was to add another value to the array and to something like:

if($array[$c]['orderCode'] == 'P')
     $array[$c]['newOrderCode'] = 0;
if($array[$c]['orderCode'] == 'I')
     $array[$c]['newOrderCode'] = 1;
if($array[$c]['orderCode'] == 'B')
     $array[$c]['newOrderCode'] = 2;

or a switch case and then order it by the new value. This would work, but my question is, is there a function I can pass the array to and an orderring string or something?

Thank you, James

In php 5.3 and above you can use usort with a closure.

$order = array('P','I','B','C','A','S','D');
usort($array, function ($a, $b) use ($order){
     return array_search($a["orderCode"], $order) - array_search($b["orderCode"], $order);
});

prior to that you have to create a sorter function

function orderCode_sorter($a, $b){
    $order = array('P','I','B','C','A','S','D');
    return array_search($a["orderCode"], $order) - array_search($b["orderCode"], $order);
}
usort($array, "orderCode_sorter");

use function user defined and choise sort by key or value you need see all list function here: http://www.php.net/manual/en/array.sorting.php