以不同的方式显示字符串 [英] Displaying strings in different ways

查看:111
本文介绍了以不同的方式显示字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个新闻显示模块。我想知道是否有一个更好的方式来显示我的文章的信息。我想要能够以不同的方式显示信息部分,具有开/关功能。例如:

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:


  1. 标题

  2. 文字


  3. 日期

  4. 作者

  1. Title
  2. Text
  3. Readmore
  4. Date
  5. Author

/ p>

or just


  1. Read more

  2. 标题

我在想这个代码,但我相信有更好的解决方案?

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆