问题
I'm going crazy with this issue, I want to get an array separated by commas(string) like example:(1,2,4,6) from a database and insert this as a variable inside a query like(select from table where id IN($variable string). Can anyone help me with this?
example:
<?php
//connect
$sql = "select id from users where id=1";
//get the results as an array
insert that variable inside this query
select from table where id IN($variable);
//
?>
i tried multiple ways and always have different issues. Please need an answer!
回答1:
implode()transforms an array into a string of values separated by the char you choose:
$arr = array(1,2,3,4,5,6,7,8,9); // make an array
$list = implode(',',$arr);
$sql = "SELECT * FROM table WHERE id IN($list)";
来源:https://stackoverflow.com/questions/16469388/making-an-array-from-database