PHP-使用循环重新排序
我有三个变量:PHP-使用循环重新排序,php,Php,我有三个变量: $title_order = 1; $image_order = 2; $content_order = 3; 用户可以重新排列/重新排序上述变量,如: $title_order = 2; $image_order = 1; $content_order = 3; 现在,根据这个变量,我想在HTML下面重新排序 <h1><?php title() ?></h1> <figure><?php th
$title_order = 1;
$image_order = 2;
$content_order = 3;
用户可以重新排列/重新排序上述变量,如:
$title_order = 2;
$image_order = 1;
$content_order = 3;
现在,根据这个变量,我想在HTML下面重新排序
<h1><?php title() ?></h1>
<figure><?php thumbnail() ?></figure>
<details><?php thumbnail() ?></details>
如何按变量编号显示,如:
<figure><?php thumbnail() ?></figure> // show image 1st if $image_orer = 1;
<h1><?php title() ?></h1> // show h1 in 2nd if $title_order = 2;
<details><?php thumbnail() ?></details> // show h1 3rd if $content_order = 3;
//如果$image\u orer=1,则首先显示图像;
//如果$title\u order=2,则在第二行显示h1;
//如果$content\u order=3,则显示h1第三;
请注意,用户可以将变量设置为1、2和3之间的任何值
所以,请告诉我如何做到这一点。$result='';
$result = '';
for ($i = 1; $i <= 3; ++$i) {
switch ($i) {
case $title_order:
$result .= '<h1>' . title() . '</h1>';
break;
case $image_order:
$result .= '<figure>' . thumbnail() . '</figure>';
break;
case $content_order:
$result .= '<details>' . thumbnail() . '</details>';
break;
}
}
echo $result;
对于($i=1;$i什么?)阅读问题,您将知道问题所在