简体   繁体   English

将单个qoute放入数组输出

[英]Put single qoute in array output

I have an array which produces output as shown below : 我有一个数组,它产生如下所示的输出:

for($i=0; $i<$cnt; $i++)
{
    $eq = $emp_q[$i];   
}

I need the output in following format : 'a','b','c' 我需要以下格式的输出: 'a','b','c'

I have tried using this : 我试过使用这个:

for($i=0; $i<$cnt; $i++)
{
    $eq .= "'$emp_q[$i]'";  
}

But above code is not giving the output I am expecting . 但是上面的代码没有给出我期望的输出。 Please help. 请帮忙。

Use implode() 使用implode()

<?php
$arr = array('a', 'b', 'c');

echo "'".implode("','", $arr)."'"; // outputs 'a','b','c'
?>

Where is you comma? 你在哪里逗号?

You have to add a comma unless i = 0; 除非i = 0,否则必须添加逗号。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM