如果我是某个数字,请更改classname [英] Change classname if i is a certain number

查看:84
本文介绍了如果我是某个数字,请更改classname的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我= 4或更高,我正在寻找一种方法来改变班级中的人数。

  $ i = 1; 
foreach($ properties ['blocks'] as $ block)
{
echo'< div class =colum1id =pic'。$ i。'style =背景图像:网址(/上传/ overige /'.$块[ 'IMAGE2']'。);>

有没有办法做到这一点? colum1需要变成colum2。

$ c> $ i = 1;
foreach($ properties ['blocks'] as $ block)
{
echo'< div class ='。($ i< 4?'colum1':'colum2' )。'id =pic'。$ i。'style =background-image:url(/ uploaded / overige /'.$ block ['image2']。');>
// --------------


Im looking for a way to change the number in a class if i=4 or higher.

        $i=1;
    foreach($properties['blocks'] as $block)
    {
        echo '<div class="colum1" id="pic'.$i.'" style="background-image:url(/uploaded/overige/'.$block['image2'].');">

Is there any way to do this ? colum1 needs to become colum2. i've been trying to use things like if else etc. but so far no success.

解决方案

$i = 1;
foreach($properties['blocks'] as $block)
{
    echo '<div class="' . ($i < 4 ? 'colum1' : 'colum2') . '" id="pic'.$i.'" style="background-image:url(/uploaded/overige/'.$block['image2'].');">
// --------------

这篇关于如果我是某个数字,请更改classname的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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