This question already has an answer here:
这个问题在这里已有答案:
- Passing an array to a query using a WHERE clause 18 answers
使用WHERE子句18将数组传递给查询
I am sure this is something simple, but I can't find it anywhere:
我确信这很简单,但我无法在任何地方找到它:
How can I change an array like this:
如何更改这样的数组:
{ [0]=> string(3) "674" [1]=> string(3) "675" [2]=> string(3) "676" [3]=> string(3) "677" }
into a simple one like this:
变成这样一个简单的:
(674,675,676,677)
For use in another SQL (IN) query?
用于另一个SQL(IN)查询?
I have tried imploding and it fails.
我试过了爆炸,它失败了。
$myarray_value = implode( ',', $myarray );
1 个解决方案
#1
2
What you are looking at is in JSON format, so just do this:
您所看到的是JSON格式,所以只需这样做:
$string = '{ [0]=> string(3) "674" [1]=> string(3) "675" [2]=> string(3) "676" [3]=> string(3) "677" }';
$array = json_decode($string);
print_r($array);
#1
2
What you are looking at is in JSON format, so just do this:
您所看到的是JSON格式,所以只需这样做:
$string = '{ [0]=> string(3) "674" [1]=> string(3) "675" [2]=> string(3) "676" [3]=> string(3) "677" }';
$array = json_decode($string);
print_r($array);