1

I want to create a lambda function, i'm doing this:

create_function('$range',  'return " ( ABS(a.price) > format_money($range["min"] AND ABS(a.price) <  format_money($range["max"]) ) OR a.price is null " ');

But the $range["min"] part breaks my attempt ... there's a problem with nested quotes and i don't know how to solve it , i don't even know if it is possible to do this or php is not that powerful, any light?

R01010010
  • 5,670
  • 11
  • 47
  • 77

4 Answers4

2

Using escaped single quotes and a ; got it to parse, don't know about the execution.

create_function('$range',  'return \' ( ABS(a.price) > format_money($range["min"] AND ABS(a.price) <  format_money($range["max"]) ) OR a.price is null \'; ');
jaudette
  • 2,305
  • 1
  • 20
  • 20
1

You cannot call variables inside of single quotes.

create_function('$range',  'return " ( ABS(a.price) > format_money('.$range["min"].' AND ABS(a.price) <  format_money('.$range["max"].') ) OR a.price is null " ');
Adam Lavin
  • 753
  • 7
  • 15
1

I was able to get this done by concatenating your values to the string like this:

create_function('$range',  'return " ( ABS(a.price) > format_money(" . $range["min"] . " AND ABS(a.price) <  format_money(" . $range["max"] . ") ) OR a.price is null "; ');

The output of that function was:

string(92) " ( ABS(a.price) > format_money(10 AND ABS(a.price) <  format_money(20) ) OR a.price is null "
Benjamin Paap
  • 2,744
  • 2
  • 21
  • 33
0

Forget it, it was wrongly composed, the correct way is:

create_function('$range',  'return " ( ABS(a.price) > ".format_money($range[\'min\'])." AND ABS(a.price) < ".format_money($range[\'max\'])." ) OR a.price is null "; ');

now it works!

R01010010
  • 5,670
  • 11
  • 47
  • 77