Php 比较Json编码数组中的每个值

Php 比较Json编码数组中的每个值,php,arrays,codeigniter,json,Php,Arrays,Codeigniter,Json,如何在不使用循环的情况下,将插入数据库的内容json\u encode中的每个a与作为速记代码的字符串进行比较?(该值是用json\u encode插入数据库的复选框) 示例 $json_encode = ["how", "are", "hello", "what"]; echo ($json_encode == 'hello') ? 'It is true' :''; 试用功能: $json_encode = ["how", "are", "hello", "what"]; echo (

如何在不使用循环的情况下,将插入数据库的内容
json\u encode
中的每个a与作为速记代码的字符串进行比较?(该值是用
json\u encode
插入数据库的复选框)

示例

$json_encode = ["how", "are", "hello", "what"];

echo ($json_encode == 'hello') ? 'It is true' :'';
试用功能:

$json_encode = ["how", "are", "hello", "what"];

echo ( in_array('hello', $json_encode) ? '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' :'' );

你能澄清一下吗?这个问题我已经读了好几遍了,但恐怕你具体想要什么还不太清楚