时间:2021-07-01 10:21:17 帮助过:11人阅读
$s = '[{"answer":"123"},{"answer":"222"},{"answer":"231"}]';select * from tbl_name where answer in (123,222,231)
$d = json_decode($s, true);
$t = join(',', array_map('current', $d));
$k = key(current($d));
$sql = "select * from tbl_name where $k in ($t)";
$data = '[{"answer":"123"},{"answer":"222"},{"answer":"231"}]';
$data = json_decode($data, true);
$answers = array();
foreach($data as $val){
array_push($answers, $val['answer']);
}
$sqlstr = "select * from table where answer in('".implode("','", $answers)."')";
#mysql_query($sqlstr) or die(mysql_error());
echo $sqlstr; // select * from table where answer in('123','222','231')