Question

I'm attempting to convert:

usort($discounts, function ($a, $b) use ($c, $d){

    $value1 = $c->do_action($a, $d, $d->value);
    $value2 = $c->do_action($b, $d, $d->value);
    return $value1 == $value2 ? 0 : ($value1 > $value2 ? 1 : -1);
});

Into a function that can be used in 5.2

Which so far I assumed I could do like this:

create_function( '$a, $b use ($that, $d)', ' $value1 = $c->do_action($a, $d, $d->value); $value2 = $c->do_action($b, $d, $d->value);return $value1 == $value2 ? 0 : ($value1 > $value2 ? 1 : -1);');

but you can't do use($c,$d) inside the first param.

Was it helpful?

Solution

Although not an ideal solution you should be able to use the global keyword to accomplish what you need:

create_function( '$a, $b', ' global $c, $d; $value1 = $c->do_action($a, $d, $d->value); $value2 = $c->do_action($b, $d, $d->value);return $value1 == $value2 ? 0 : ($value1 > $value2 ? 1 : -1);');
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top