带有字符串键或嵌套引号的数组到php中的lambda函数中

时间:2023-02-03 18:01:50

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

我想创建一个lambda函数,我这样做:

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?

但$ range [“min”]部分打破了我的尝试......嵌套引号存在问题,我不知道如何解决它,我甚至不知道是否有可能这样做或者php不是那强大,任何光明?

4 个解决方案

#1


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 \'; ');

#2


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 " ');

#3


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 "

#4


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!

现在它的作品!

#1


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 \'; ');

#2


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 " ');

#3


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 "

#4


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!

现在它的作品!