I am trying to sort an array "$refs" by comparing it to a string "$term" using uasort and regex :
this is my array :
Array
(
[0] => Array
(
[id] => 71063
[uniqid] => A12171063
[label] => Pratique...
)
[1] => Array
(
[id] => 71067
[uniqid] => A12171067
[label] => Etre....
)
...
and my code :
uasort($refs, function ($a, $b) use ($term) {
$patern='/^' . $term . '/';
if ((preg_match($patern, $a['label']) - preg_match($patern, $b['label']) )== 0) {
return 0;
}
if ((preg_match($patern, $a['label']) - preg_match($patern, $b['label'])) == 1) {
return -1;
}
if ((preg_match($patern, $a['label']) - preg_match($patern, $b['label'])) == -1) {
return 1;
}
});
I have only 0 like returns, where is my mistake !:/ Thanks
$refs = $a = $b = $term = ???$term, I wonder? If it contains regex metacharacters, you probably need topreg_quoteit.