foreach($reciveValue as $value){
echo $value.",";// Result: based on user input like:10,11,12,13,14
}
echo $value; // Result: 14
内部循环的结果是:10,11,12,13,14
和外部循环是:14
我想使用循环外的所有值
答案 0 :(得分:1)
使用以下代码将您的数组值以逗号分隔
implode(",", $reciveValue)
答案 1 :(得分:0)
@Support Techcherry如果要使用外部数组的所有值 循环然后你可以使用implode()函数,下面是一个例子 理解
<?php
$reciveValue = array(10,11,12,13,14); // suppose this is your array
foreach($reciveValue as $value){
echo $value.",";// Result: based on user input like:10,11,12,13,14
}
echo "<br>";
echo implode(',', $reciveValue); // here implode() function convert the array value in the string form
?>
尝试一下,它会帮助你
答案 2 :(得分:0)
试试这个:
$value = '';
foreach($reciveValue as $val){
$value .= $val.",";// Result: based on user input like:10,11,12,13,14
}
echo rtrim($value, ',');
答案 3 :(得分:0)
感谢大家发帖回答 每个答案对我都很有帮助 但最后我得到了我的解决方案
$result="";
foreach($reciveValue as $value)
{
$result=$value.",".$result;
}
echo $result;