我正在创建一个新闻显示模块。我想知道是否有更好的方式来显示我的文章信息。我希望能够以不同的方式显示信息部分,具有开/关功能。例如:
或只是
我正在考虑这段代码,但我相信这是一个更好的解决方案?
<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>
答案 0 :(得分:0)
你可以这样做:
$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'];