EDIT: I rewrote my post in order to be clearer and provide a standalone case with real values (no Ajax anymore).
I have 2 arrays that are exactly identical except that one has the same values but cleaned (html, special chars, etc..).
I would like to evaluate the sorting against "arrayClean" but to sort "arrayOriginal" instead (not arrayClean) according to that evaluation.
So, this is what I have:
<?php
$arrayOriginal  = array(
    array('id' => '100','surface' => '<span>300</span>','whatever' => 'qSDqsd'),
    array('id' => '5465','surface' => '100 ch','whatever' => 'ghjkghjk'),
    array('id' => '40489','surface' => '<b>1000</b>','whatever' => 'fgsdfg')
);
$arrayClean = array(
    array('id' => '100','surface' => '300','whatever' => 'qSDqsd'),
    array('id' => '5465','surface' => '100','whatever' => 'ghjkghjk'),
    array('id' => '40489','surface' => '1000','whatever' => 'fgsdfg')
);
usort($arrayOriginal, function($a, $b) use (&$arrayClean) {
    return $a['surface'] < $b['surface'];
});
echo '<pre>'; print_r($arrayOriginal); echo '</pre>';
?>
here is what I get (which is wrong as the arrayClean doesn't seem to be taken into account for the sorting) :
Array
(
[0] => Array
    (
        [id] => 100
        [surface] => <span>300</span>
        [whatever] => qSDqsd
    )
[1] => Array
    (
        [id] => 40489
        [surface] => <b>1000</b>
        [pwhatever] => fgsdfg
    )
[2] => Array
    (
        [id] => 5465
        [surface] => 100 ch
        [whatever] => ghjkghjk
    )
)
But if I use arrayClean alone, just to check if the sorting script is right:
usort($arrayClean, function($a, $b) {
    return $a['surface'] < $b['surface'];
});
echo '<pre>'; print_r($arrayClean); echo '</pre>';
Then the result is what I expect it to be:
Array
(
[0] => Array
    (
        [id] => 40489
        [surface] => 1000
        [whatever] => fgsdfg
    )
[1] => Array
    (
        [id] => 100
        [surface] => 300
        [whatever] => qSDqsd
    )
[2] => Array
    (
        [id] => 5465
        [surface] => 100
        [whatever] => ghjkghjk
    )
)
So it seems that evaluating arrayClean but sorting arrayOriginal accordingly doesn't work. It only evaluates AND sort arrayOriginal. Do I use "use()" wrong ? Should I use something else ?
Thank you.
 
     
    