Php 仅在其他情况下使用调整逗号
嗨,上面程序的输出给我的是A,f,d,现在我不想要两个值之间的空格,如果我省略其中任何一个,请告诉我怎么做 请注意,我只需要在else语句不能使用循环时使用Php 仅在其他情况下使用调整逗号,php,Php,嗨,上面程序的输出给我的是A,f,d,现在我不想要两个值之间的空格,如果我省略其中任何一个,请告诉我怎么做 请注意,我只需要在else语句不能使用循环时使用 谢谢。您能使用阵列吗?你可以这样做 <?php $one = "A"; $two = "f"; $three = ""; $four = "d"; $output = ""; $output = $one.",".$two.",".$three.",".$four; if ($four == "") { echo $outpu
谢谢。您能使用阵列吗?你可以这样做
<?php
$one = "A";
$two = "f";
$three = "";
$four = "d";
$output = "";
$output = $one.",".$two.",".$three.",".$four;
if ($four == "") {
echo $output;
}
elseif ($three == "") {
echo $output;
}
elseif ($two == "") {
echo $output;
}
elseif ($one == "") {
echo $output;
}
?>
检查这里:Thanx这对我很有帮助,这是我的一个作业,我想我可以使用数组。我想这是你的评估,试着自己做,而不是问这里,因为这是你的课堂作业。祝你好运。非常感谢……我也尝试了很多,我的导师把我弄糊涂了,我不得不在这里问!谢谢,这正是我想要的!
$output = implode(',', array_filter(array($one, $two, $three, $four)));
<?php
$one = "A";
$two = "f";
$three = "";
$four = "d";
$output = "";
if($output && $one){
$output .= ",".$one;
}else{
$output .= $one;
}
if($output && $two){
$output .= ",".$two;
}else{
$output .= $two;
}
if($output && $three){
$output .= ",".$three;
}else{
$output .= $three;
}
if($output && $four){
$output .= ",".$four;
}else{
$output .= $four;
}
echo $output;
?>