gpt4 book ai didi

php - 以不同方式显示字符串

转载 作者:行者123 更新时间:2023-11-28 14:04:43 25 4
gpt4 key购买 nike

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

  1. 职位
  2. 正文
  3. 阅读更多
  4. 日期
  5. 作者

或者只是

  1. 阅读更多
  2. 职位

我正在考虑这段代码,但我相信有更好的解决方案?

<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'];

关于php - 以不同方式显示字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10069720/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com