if语句之外的回声

时间:2011-05-04 01:13:12

标签: php if-statement echo

这是我的代码

if ($follower_username == $user){

echo $followed_username.",";

};

当它运行时,它会回显echos name,name2,name3,name4

然而,当我这样做时

if ($follower_username == $user){

$names = $followed_username.",";
};

echo $name`;

它只输出name4,

是什么导致它只提取姓氏?

谢谢!

2 个答案:

答案 0 :(得分:6)

if ($follower_username == $user) {
  $names .= $followed_username;
}
echo $names;

答案 1 :(得分:0)

试试这个:

//outside your loop:
$names = '';

while(){
    //...code

   if ($follower_username == $user){

   $names .= $followed_username.",";
   };

   echo $names;
}