duan5991518 2013-01-01 23:06
浏览 116
已采纳

从两个已知单词生成随机单词

I can do this with numbers:

<?=number_format(mt_rand(0,1));?>

What I want to do is, instead of 0 or 1, echo the words firstclass or secondclass.

This is because I cannot use numbers as class identifiers in CSS.

Essentially, this is just for displaying random stuff within a list and prepending the class identifier with either firstclass or secondclass.

.firstclass {display:none;}

I am not ace with PHP, so I guess I need to set up an array, and somehow attribute:

0 = firstclass
1 = secondclass

within the array, so that I can get my little test script working.

Any suggestions?

  • 写回答

5条回答 默认 最新

  • dongqiaochi2711 2013-01-01 23:08
    关注

    You can use a ternary-style if statement if you only have two possibilities:

    <?=(mt_rand(0,1) == 0) ? 'firstclass' : 'secondclass'?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试,帮帮忙吧
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建