php - Closure with confusing usort -


i trying rewrite co-developers script , ran across little gem, life of me cannot understand does, less how refactor it. explain me does, , if interpretation of code correct?

the original code:

$f = "return (${$v[0]}['{$k}'] - ${$v[1]}['{$k}']);"; usort($results, create_function('$a,$b',$f)); 

my attempt , rewriting closure:

$f = function ($k,$v) {     return ($v[0][$k] - $v[1][$k]); };  usort($results, $f($k, $v)); 

edit

for clarity, $k random string, , $v array of either ['a','b'] or array of ['b','a']

i'm lost on attempt was, maybe this?

usort($results, function () use ($k,$v)  {     return ($v[0][$k] - $v[1][$k]); }); 

you have this

$f = function ($k,$v) {     return ($v[0][$k] - $v[1][$k]); };  usort($results, $f); 

read more closures , usort in php.net


Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -