[英]php get the values from the array as like format
I have an array like this 我有这样的数组
Array
(
[0] => T-shirts
[1] => Evening Dresses
[2] => Dresses
[3] => Clothes
)
Here I want to get the values of the array and add "" for each values and add , after each value So the valus should finally come like this 在这里,我要获取数组的值,然后为每个值添加“”,并在每个值之后添加,因此,值最终应该像这样
IN("T-shirts","Evening Dresses","Dresses","Clothes")
so for this I made my code like this 所以为此我使我的代码像这样
$category_pool = '';
foreach($categoryArray as $categoryArr)
$category_pool .= $categoryArr.',';
$category_pool = ((strpos($category_pool, ',') === false) ? (' = '.$category_pool.' ') : (' IN ("'.rtrim($category_pool, ',').'") '));
But here it is getting the value like 但是在这里它得到的价值就像
IN ("T-shirts,Evening Dresses,Dresses,Clothes")
So can someone tell me how to make this value to come like 有人可以告诉我如何实现这一价值吗?
IN("T-shirts","Evening Dresses","Dresses","Clothes")
Any help and suggestions will be really appreciable. 任何帮助和建议都是非常可取的。 Thanks
谢谢
'IN('
. implode(
',',
array_map(function ($val) {
return sprintf('"%s"', $val);
}, $categoryArray)
)
. ')';
Quick solution is: 快速解决方案是:
change your fragment: 改变你的片段:
$category_pool = '';
foreach($categoryArray as $categoryArr)
$category_pool .= $categoryArr.',';
$category_pool = ((strpos($category_pool, ',') === false) ? (' = '.$category_pool.' ') : (' IN ("'.rtrim($category_pool, ',').'") '));
with one my line: 我的一行:
$category_pool = 'IN ( "' . implode('","',$categoryArray).'")';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.