以不同的方式显示字符串 [英] Displaying strings in different ways
本文介绍了以不同的方式显示字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在创建一个新闻显示模块。我想知道是否有一个更好的方式来显示我的文章的信息。我想要能够以不同的方式显示信息部分,具有开/关功能。例如:
I'm creating a module for news display. I'd like to know if there's a better way to display info of my article. I want to be able to display info parts in different ways, with on/off functionality. For example:
- 标题
- 文字
- 日期
- 作者
- Title
- Text
- Readmore
- Date
- Author
/ p>
or just
- Read more
- 标题
我在想这个代码,但我相信有更好的解决方案?
I'm thinking of this code, but I believe there's a better solution?
<div id="pos1">
<?php
if ( show = 1 ) {
echo 'Here will be title';
elseif ( show = 2 ) {
echo 'Here will be text';
elseif ( show = 3 ) {
echo 'Here will be readmore';
.....
else { $string = 'nothing here'; }
?></div>
<div id="pos2">
<?php
if ( showsecond = 1 ) {
echo 'Here will be title';
elseif ( showsecond = 2 ) {
echo 'Here will be text';
elseif ( showsecond = 3 ) {
echo 'Here will be readmore';
.....
else { $string = 'nothing here'; }
?></div>
推荐答案
您可以这样做:
$info = array(
1 => 'This will be the title',
2 => 'this will be the text',
3 => 'This is the readmore',
4 => 'Date',
5 => 'Author'
);
echo $info[$show];
编辑:
$info = array(
1 => array(
'text' => 'This will be the title',
'styles' => 'styling info goes here'
),
2 => array(
'text' => 'This will be the author',
'styles' => 'styling info goes here'
),
3 => array(
'text' => 'This will be the date',
'styles' => 'styling info goes here'
)
);
echo $info[$show]['text'];
这篇关于以不同的方式显示字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文