Question: I have an array of scripts

```
Array
(
    [0] => /js/ionslider/ion.rangeSlider.min.js
    [1] => /media/jquery/jQuery-2.1.4.min.js
    [2] => /media/bootstrap/js/bootstrap.min.js
    [3] => /widgets/wid_menu/js/menu.js
)

```

How can I sort this to get results:

```
Array
(
    [0] => /media/jquery/jQuery-2.1.4.min.js            
    [1] => /media/bootstrap/js/bootstrap.min.js
    [2] => /js/ionslider/ion.rangeSlider.min.js        
    [3] => /widgets/menu/js/menu.js
)

```

E.g put jQuery script and bootstrap at the top. 
P.S jQuery version file may be changed in the future.
Thanks!

Answer: 
You can use usort($arr, "cmp"); and use a custom sorting function. Then in that sorting function you can define a preg\_match that can fit your needs with a regular expression that validates for a string that contains "jquery" with any version and "bootstrap".

[Sorting by Regex Groups in PHP](https://stackoverflow.com/questions/8447281/sorting-by-regex-groups-in-php)
Maybe it's better to call it 'reordering' not 'sorting'

However, there are various ways you can do it.

I just made up a simple one:

```
$current = array(
    '/js/ionslider/ion.rangeSlider.min.js',
    '/media/jquery/jQuery-2.1.4.min.js',
    '/media/bootstrap/js/bootstrap.min.js',
    '/widgets/wid_menu/js/menu.js',
);

$priorities = array(
    'jquery',
    'bootstrap',
    'menu',
    );

function reorder($array, $priors){
    $result = array();
    foreach ($priors as $p) {
        $result = array_unique (array_merge ($result , preg_grep ('/'.$p.'/i', $array)));
    }

    return array_unique (array_merge ($result , $array));
}

echo '<pre>'.print_r(reorder($current,$priorities),true).'</pre>';

```