0
如何将插入数据库的内容json_encode
与作为简写代码的字符串进行比较而不使用循环? (此值是复选框,在数据库与json_encode
插入)与Json编码数组中的每个值进行比较
例
$json_encode = ["how", "are", "hello", "what"];
echo ($json_encode == 'hello') ? 'It is true' :'';
如何将插入数据库的内容json_encode
与作为简写代码的字符串进行比较而不使用循环? (此值是复选框,在数据库与json_encode
插入)与Json编码数组中的每个值进行比较
例
$json_encode = ["how", "are", "hello", "what"];
echo ($json_encode == 'hello') ? 'It is true' :'';
的代码的“圆一个回合一点点'做事的方式,但这应该可以做到这一点:
$json_encode = '["how", "are", "hello", "what"]';
echo (in_array('hello', json_decode($json_encode)) ? 'It is true' :'');
您的初始$ json_encode没有正确设置为正确的JSON字符串,并且需要解码才能稍后使用数组检查功能。
更好的方法可能:
$json_string = json_encode(array("how", "are", "hello", "what"));
echo (in_array('hello', json_decode($json_string)) ? 'It is true' :'');
尝试用in_array()
功能:
$json_encode = ["how", "are", "hello", "what"];
echo (in_array('hello', $json_encode) ? 'It is true' :'');
你能澄清一下,我读过这个问题了几次,但恐怕它不是太清楚你特别希望 – SW4