Reputation: 1939
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.
Upvotes: 0
Views: 137
Reputation: 219894
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);');
Upvotes: 1