duandiao3961 2011-01-31 22:22
浏览 44

使用变量来回显设置数据

I can't think of how to do this in my head so I would like someone to lay this out for me. What I am trying to do is allow a user to set a custom greeting for a email using a variable. So for example, in the body of the email, they'll place "$greeting" which will echo out a random greeting they set {'hey', 'hello', 'hi'}.

can someone explain how I would achieve this?

  • 写回答

4条回答 默认 最新

  • douqie1852 2011-01-31 22:25
    关注

    define your possible greetings in an array

    $greetings = array('hey', 'hello', 'hi');
    

    echo out a random one

    echo $greetings[array_rand($greetings)];
    

    or

    shuffle($greetings);
    echo $greetings[0];
    
    评论

报告相同问题?